#T362. LETTERS

LETTERS

Description

Given a matrix of uppercase letters with dimensions row×colrow \times col, 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 RR and columns SS of the letter matrix, where 1R,S201 \leq R, S \leq 20. The following RR lines each contain SS uppercase letters representing the matrix.

Output Format

The maximum number of distinct letters that can be traversed.

3 6
HFDFFB
AJHGDH
DGAGEH

6