#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
vector<vector<char>>grid;
vector<vector<ll>>vis;
ll cox[8] = {1, -1, 0, 0, 1, 1, -1, -1};
ll coy[8] = {0, 0, -1, 1, 1, -1, 1, -1};
bool ok(ll nx,ll ny){
if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny])return 1;
return 0;
}
ll mx=0,cnt=0;
void dfs(ll x,ll y){
vis[x][y]=1;
cnt++;
mx=max(mx,cnt);
for(int i=0;i<8;i++){
ll nx=x+cox[i];
ll ny=y+coy[i];
char ch=grid[x][y]+1;
if(ok(nx,ny)&&grid[nx][ny]==ch){
dfs(nx,ny);
}
}
}
int main() {
do{
int i=1;
cin>>n>>m;
if(n==0&&m==0)break;
vis.assign(n + 1, vector<ll>(m + 1, 0));
grid.assign(n+1, vector<char>(m + 1, 0));
mx=0,cnt=0;
for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>grid[i][j];
for(int i=0;i<n;i++)for(int j=0;j<m;j++){
if(!vis[i][j]&&grid[i][j]=='A'){
cnt=0;
dfs(i,j);
}
}
cout<<"Case "<<i<<": "<<mx<<"\n";
}while(n!=0&&m!=0);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmxsIG4sbTsKdmVjdG9yPHZlY3RvcjxjaGFyPj5ncmlkOwp2ZWN0b3I8dmVjdG9yPGxsPj52aXM7CgpsbCBjb3hbOF0gPSB7MSwgLTEsIDAsIDAsIDEsIDEsIC0xLCAtMX07CmxsIGNveVs4XSA9IHswLCAwLCAtMSwgMSwgMSwgLTEsIDEsIC0xfTsKYm9vbCBvayhsbCBueCxsbCBueSl7CiAgICBpZiAobnggPj0gMCAmJiBueCA8IG4gJiYgbnkgPj0gMCAmJiBueSA8IG0gJiYgIXZpc1tueF1bbnldKXJldHVybiAxOwoKICAgIHJldHVybiAwOwp9CmxsIG14PTAsY250PTA7CnZvaWQgZGZzKGxsIHgsbGwgeSl7CiAgICB2aXNbeF1beV09MTsKICAgIGNudCsrOwogICAgbXg9bWF4KG14LGNudCk7CiAgICBmb3IoaW50IGk9MDtpPDg7aSsrKXsKICAgICAgICBsbCBueD14K2NveFtpXTsKICAgICAgICBsbCBueT15K2NveVtpXTsKICAgICAgICBjaGFyIGNoPWdyaWRbeF1beV0rMTsKICAgICAgICBpZihvayhueCxueSkmJmdyaWRbbnhdW255XT09Y2gpewogICAgICAgICAgICBkZnMobngsbnkpOwogICAgICAgIH0KICAgIH0KCn0KaW50IG1haW4oKSB7CiAgICBkb3sKICAgICAgICBpbnQgaT0xOwogICAgICAgIGNpbj4+bj4+bTsKICAgICAgICBpZihuPT0wJiZtPT0wKWJyZWFrOwogICAgICAgIHZpcy5hc3NpZ24obiArIDEsIHZlY3RvcjxsbD4obSArIDEsIDApKTsKICAgICAgICBncmlkLmFzc2lnbihuKzEsIHZlY3RvcjxjaGFyPihtICsgMSwgMCkpOwogICAgICAgIG14PTAsY250PTA7CiAgICAgICAgZm9yKGludCBpPTA7aTxuO2krKylmb3IoaW50IGo9MDtqPG07aisrKWNpbj4+Z3JpZFtpXVtqXTsKICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKWZvcihpbnQgaj0wO2o8bTtqKyspewogICAgICAgIGlmKCF2aXNbaV1bal0mJmdyaWRbaV1bal09PSdBJyl7CiAgICAgICAgICAgIGNudD0wOwogICAgICAgICAgICBkZnMoaSxqKTsKICAgICAgICB9CiAgICB9CiAgICAgICAgY291dDw8IkNhc2UgIjw8aTw8IjogIjw8bXg8PCJcbiI7CgogICAgfXdoaWxlKG4hPTAmJm0hPTApOwoKfQo=