#t344. 字符数

字符数

Count of Letters

Problem Background

Special for beginners, ^_^

Problem Description

You are given an uppercase letter matrix of size R×SR \times S. Starting from the top-left corner, you may move up, down, left, or right, and you may not step onto a letter you have already visited. What is the maximum number of distinct letters you can visit?

Input Format

The first line contains the number of rows RR and the number of columns SS of the letter matrix, with 1≤R,S≤201\le R,S\le 20.

Then RR lines follow, each containing a row of the SS-column letter matrix.

Output Format

The maximum number of distinct letters that can be visited.

Sample Input

3 6
HFDFFB
AJHGDH
DGAGEH

Sample Output

6

Constraints

1s, 1024KiB for each test case.