cho.sh
Notes
Loading...

Alphabet Path

Time limit

2s

Memory limit

256 MB

Problem

A board has RRR rows and CCC columns. Each cell contains one uppercase English letter. A piece starts in the upper-left cell, row 111 and column 111.

The piece may move to one vertically or horizontally adjacent cell. It may enter a cell only if that cell's letter is different from every letter on the cells visited so far. In other words, the path cannot contain the same letter twice.

Find the maximum number of cells the piece can visit, including the starting cell.

Input

The first line contains RRR and CCC, separated by a space. (1≤R,C≤201 \le R,C \le 201≤R,C≤20)

Each of the next RRR lines contains CCC uppercase English letters with no spaces, describing the board.

Output

Print the maximum number of cells the piece can visit.