#D1. Letter Game
Letter Game
Description
A single-player game with the following rules:
On an R-row by C-column grid, each cell contains a letter from to . The game starts from the top-left corner (first row, first column) and moves step by step to adjacent cells (up, down, left, right). The only constraint is that each letter on the path can only appear once.
The goal of the game is to traverse the longest possible path. Please write a program to calculate the maximum number of steps that can be taken on a given chessboard.
Format
Input
The first line contains two integers and separated by a space. The following lines each contain letters, representing the state of each row on the chessboard.
Output
There is only one line, which is the longest step count you calculated.
Samples
input1
2 4
CAAB
ADCB
output1
3
input2
3 6
HFDFFB
AJHGDH
DGAGEH
output2
6
Instructions
Data range: .