I have an n x m matrix consisting of non-negative integers. For example:
n x m
2 3 4 7 1 1 5 2 6 2 4 3 4 2 1 2 1 2 4 1 3 1 3 4 1 2 1 4 3 2 6 9 1 6 4
You could use state space planning. For example, using A* (or one of its variants) coupled with an heuristic f = g + h like this:
f = g + h