problem-3-13

You will be given a grid of numbers of size r by c (r-rows,c-columns). And you have to find the length of longest L that can be formed by same numbers. L shape will be one vertical line,and from the bottom most point one horizontal line towards the right.

Length of L= No of elements in the shape formed.

Lets say the grid is of size 4 by 4 :

1 2 3 4
5 6 7 8
5 6 6 7
5 5 5 7

Here the longest L is of size 5 and of the element 5.

Note:
L can contain even a single element in horizontal or vertical line.

Input:

First line will contain two space separated integers r and c. Followed by r lines containing c space separated integers(Xij) in each line

Output:

Print the length of longest L possible

Constraints:

1 ≤ r , c ≤ 10^3

1 ≤ Xij ≤ 10^5

SAMPLE INPUT
4 4
1 2 3 4
5 6 7 8
5 6 6 7
5 5 5 7

SAMPLE OUTPUT
5

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions: