Given a n*m matrix, M of positive integers. Here, the adjacent cells of a particular cell is the up, down, left and right cells. Like for cell M[i][j] the adjacent cells are M[i-1][j], M[i+1][j], M[i][j-1] and M[i][j+1] respectively. 
The problem is to find out a maximum area(i.e. maximum number of adjacent cells) of this matrix which contains exactly two different numbers.

For an example: M = [[5, 3, 2, 5, 5],
                     [2, 1, 2, 5, 3],
                     [6, 1, 5, 2, 5],
                     [5, 2, 5, 3, 5],
                     [4, 6, 8, 9, 6]]
Here the maximum area contains 10 cells. And the area is:
                    [[., ., 2, 5, 5],
                     [., ., 2, 5, .],
                     [., ., 5, 2, .],
                     [5, 2, 5, ., .],
                     [., ., ., ., .]]

What is the most efficient way to find the maximum area?