#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) {
return (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny]);
}
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);
}
}
cnt--;
}
int main() {
int case_num = 1;
while (true) {
cin >> n >> m;
if (n == 0 && m == 0) break;
vis.assign(n, vector<ll>(m, 0));
grid.assign(n, vector<char>(m));
mx = 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 " << case_num << ": " << mx << "\n";
case_num++;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpsbCBuLCBtOwp2ZWN0b3I8dmVjdG9yPGNoYXI+PiBncmlkOwp2ZWN0b3I8dmVjdG9yPGxsPj4gdmlzOwoKbGwgY294WzhdID0gezEsIC0xLCAwLCAwLCAxLCAxLCAtMSwgLTF9OwpsbCBjb3lbOF0gPSB7MCwgMCwgLTEsIDEsIDEsIC0xLCAxLCAtMX07Cgpib29sIG9rKGxsIG54LCBsbCBueSkgewogICAgcmV0dXJuIChueCA+PSAwICYmIG54IDwgbiAmJiBueSA+PSAwICYmIG55IDwgbSAmJiAhdmlzW254XVtueV0pOwp9CgpsbCBteCA9IDAsIGNudCA9IDA7Cgp2b2lkIGRmcyhsbCB4LCBsbCB5KSB7CiAgICB2aXNbeF1beV0gPSAxOwogICAgY250Kys7CiAgICBteCA9IG1heChteCwgY250KTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IDg7IGkrKykgewogICAgICAgIGxsIG54ID0geCArIGNveFtpXTsKICAgICAgICBsbCBueSA9IHkgKyBjb3lbaV07CiAgICAgICAgY2hhciBjaCA9IGdyaWRbeF1beV0gKyAxOwoKICAgICAgICBpZiAob2sobngsIG55KSAmJiBncmlkW254XVtueV0gPT0gY2gpIHsKICAgICAgICAgICAgZGZzKG54LCBueSk7CiAgICAgICAgfQogICAgfQogICAgY250LS07Cn0KCmludCBtYWluKCkgewogICAgaW50IGNhc2VfbnVtID0gMTsKCiAgICB3aGlsZSAodHJ1ZSkgewogICAgICAgIGNpbiA+PiBuID4+IG07CiAgICAgICAgaWYgKG4gPT0gMCAmJiBtID09IDApIGJyZWFrOwoKICAgICAgICB2aXMuYXNzaWduKG4sIHZlY3RvcjxsbD4obSwgMCkpOwogICAgICAgIGdyaWQuYXNzaWduKG4sIHZlY3RvcjxjaGFyPihtKSk7CiAgICAgICAgbXggPSAwOwoKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBtOyBqKyspCiAgICAgICAgICAgICAgICBjaW4gPj4gZ3JpZFtpXVtqXTsKCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBtOyBqKyspIHsKICAgICAgICAgICAgICAgIGlmICghdmlzW2ldW2pdICYmIGdyaWRbaV1bal0gPT0gJ0EnKSB7CiAgICAgICAgICAgICAgICAgICAgY250ID0gMDsKICAgICAgICAgICAgICAgICAgICBkZnMoaSwgaik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGNvdXQgPDwgIkNhc2UgIiA8PCBjYXNlX251bSA8PCAiOiAiIDw8IG14IDw8ICJcbiI7CiAgICAgICAgY2FzZV9udW0rKzsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=