A Matter of Size

Time limit: 0.1s Memory limit: 32MB Input: Output:

George has recently enrolled in a Kabbalah seminar, where a few cultured savants debate on the concealed wisdom of the Bible. In particular, their favorite hobby is searching the Bible for long sequences of equal letters.

Firstly, the seminar master selects an N×MN \times M rectangle of characters Ci,jC_{i,j} from the holy scriptures. Afterwards, the adepts search in all directions (horizontal, vertical and diagonal) for contiguous sequences of equal letters and the longer the sequence found, the greater the glory for the finder.

Task

Help George prove his wisdom by finding the longest sequence of equal letters!

Input data

The first line contains two integers NN and MM. Other NN lines follow, each containing a string consisting of MM lowercase letters from a to z (translated from the Hebrew alphabet).

Output data

You need to write a single line with an integer: the longest sequence of equal letters present in the bible fragment.

Constraints and clarifications

  • 1N,M1 0001 \leq N, M \leq 1 \ 000
  • Ci,jC_{i,j} is a lowercase letter from a to z for each i<Ni < N, j<Mj < M.
# Points Constraints
1 5 Examples.
2 25 N=1N = 1
3 40 N,M10N, M \leq 10
4 30 No additional constraints.

Example 1

stdin

4 6
uieiki
zqnitz
chquth
keinoi

stdout

2

Explanation

The longest sequence consists of 22 vertical letters i.

Example 2

stdin

7 5
fjqhr
aqnrb
baqah
zanqi
oahqq
rovna
zgpao

stdout

4

Explanation

The longest sequence consists of 44 diagonal letters q.

Log in or sign up to be able to send submissions!