#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;
}
