#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
typedef long long ll;
const int N = 50+5;
const int INF = 1e9;
const int MOD = 1e9+7;
int n, m;
char c[N][N];
int dp[N][N];
int vis[N][N];
int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy[] = {0, 1, 1, 1,0 , -1, -1, -1};
//dp[i][j]: the longest consecutive sequence start at (i,j)
int dfs(int x, int y){
dp[x][y] = 1;
int mx = 0;
for(auto i:dx){
for(auto j:dy){
int nx = x+i, ny = y+j; //new_x, new_y
if (nx<0 || ny<0 || nx>=n || ny>=m) continue;
if (c[nx][ny]-c[x][y] != 1) continue;
if (dp[nx][ny] != 0) {
mx = max(mx, dp[nx][ny]);
continue;
}
mx = max(mx, dfs(nx, ny));
}
}
dp[x][y] += mx;
return dp[x][y];
}
int main()
{
IOS
// freopen("input.txt", "r", stdin);
int tc = 1;
while(1){
cin >> n >> m;
if (n == 0 && m == 0) break;
for(int i=0; i<n; i++){
for (int j=0; j<m; j++){
cin >> c[i][j];
}
}
memset(dp, 0, sizeof dp);
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if (dp[i][j] == 0) dfs(i, j);
}
}
int ans = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if (c[i][j] == 'A') ans = max(ans, dp[i][j]);
}
}
cerr << "Case " << tc++ << ": " << ans << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgd2hhdF9pcyh4KSBjZXJyIDw8ICN4IDw8ICIgaXMgIiA8PCB4IDw8IGVuZGw7CiNkZWZpbmUgSU9TIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZSgwKTsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CmNvbnN0IGludCBOID0gNTArNTsKY29uc3QgaW50IElORiA9IDFlOTs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