/*
*** PATIENCE ABOVE PERFECTION ***
"When in doubt, use brute force. :D"
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define nline cout<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define ull unsigned long long int
#define ll long long int
#define pii pair<int,int>
#define MAXX 55
#define fr(a,b,i) for(int i=a;i<b;i++)
vector<int>G[MAXX];
int X[]={1,1,0,-1,-1,-1,0,1};
int Y[]={0,1,1,1,0,0,-1,-1,-1};
int d=0,h,w;
char ch[MAXX][MAXX];
bool vis[MAXX][MAXX];
int maxx=-1;
struct data
{
int x,y;
void set(int _x,int _y)
{
x=_x;
y=_y;
}
};
void dfs(data src,int d)
{
vis[src.x][src.y]=true;
for(int i=0;i<8;i++)
{
int xx=X[i]+src.x;
int yy=Y[i]+src.y;
if(xx>=0 and xx<w and yy>=0 and yy<h and (not vis[xx][yy]) and ((char)(ch[src.x][src.y]+1))==ch[xx][yy])
{
data x;
x.set(xx,yy);
dfs(x,++d);
}
}
maxx=max(maxx,d);
}
int main()
{
cin>>h>>w;
int final=1;
while(h!=0 and w!=0)
{
fr(0,h,i)
fr(0,w,j)
cin>>ch[i][j];
data point;
vector<data>v;
fr(0,h,i)
{
fr(0,w,j)
{
if(ch[i][j]=='A')
{
point.set(i,j);
v.pb(point);
}
}
}
maxx=0;
int f=0;
for(int i=0;i<v.size();i++)
{
memset(vis,false,sizeof vis);
dfs(v[i],0);
}
//cout<<v.size()<<endl;
if(not v.empty())
printf("Case %d: %d",final++,maxx+1);
else
printf("Case %d: %d",final++,0);
nline;
cin>>h>>w;
}
return 0;
}
LyoKICAgICAgKioqIFBBVElFTkNFIEFCT1ZFIFBFUkZFQ1RJT04gKioqCiAgICAgICAgIldoZW4gaW4gZG91YnQsIHVzZSBicnV0ZSBmb3JjZS4gOkQiCiovCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgcGIgcHVza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