in fact,you want to find all connected components.
BFS and DFS are famous algorithm about this.and for this problem you can use DFS.so you assume for each number you have a vertex.and this vertex connected by only going up, down, left and right that their numbers are equal.repeat DFS until all vertex will mark.now find a component which it has a maximum number in this graph.