#T362. LETTERS
LETTERS
Description
Given a matrix of uppercase letters with dimensions , starting from the top-left corner, you can move in four directions: up, down, left, or right. However, you cannot move to a cell containing a letter that has already been visited. Determine the maximum number of distinct letters that can be traversed.
Input Format
The first line contains the number of rows and columns of the letter matrix, where . The following lines each contain uppercase letters representing the matrix.
Output Format
The maximum number of distinct letters that can be traversed.
3 6
HFDFFB
AJHGDH
DGAGEH
6