#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int main() {
for (int cs = 1;; cs++) {
int R, C; cin >> R >> C; if (R==0) return 0;
vector<string> V(R);
vector<vector<int> > dp(R, vector<int>(C, -1e9));
for (int i = 0; i < R; i++) {
cin >> V[i];
}
int res = 0;
for (char c = 'A'; c <= 'Z'; c++) {
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (V[i][j] != c) continue;
if (c == 'A') dp[i][j] = 1;
for (int k = 0; k < 8; k++) {
int r = i + dx[k], c = j + dy[k];
if (r >= 0 && c >= 0 && r < R && c < C &&
V[r][c] == V[i][j] - 1) {
dp[i][j] = max(dp[i][j], dp[r][c] + 1);
}
}
res = max(res, dp[i][j]);
}
}
}
cout << "Case " << cs << ": " << res << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgZHhbOF0gPSB7MSwgMSwgMSwgMCwgMCwgLTEsIC0xLCAtMX07CmNvbnN0IGludCBkeVs4XSA9IHsxLCAwLCAtMSwgMSwgLTEsIDEsIDAsIC0xfTsKaW50IG1haW4oKSB7CiAgICBmb3IgKGludCBjcyA9IDE7OyBjcysrKSB7CiAgICAgICAgaW50IFIsIEM7IGNpbiA+PiBSID4+IEM7IGlmIChSPT0wKSByZXR1cm4gMDsKICAgICAgICB2ZWN0b3I8c3RyaW5nPiBWKFIpOwogICAgICAgIHZlY3Rvcjx2ZWN0b3I8aW50PiA+IGRwKFIsIHZlY3RvcjxpbnQ+KEMsIC0xZTkpKTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IFI7IGkrKykgewogICAgICAgICAgICBjaW4gPj4gVltpXTsKICAgICAgICB9CiAgICAgICAgaW50IHJlcyA9IDA7CiAgICAgICAgZm9yIChjaGFyIGMgPSAnQSc7IGMgPD0gJ1onOyBjKyspIHsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBSOyBpKyspIHsKICAgICAgICAgICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgQzsgaisrKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKFZbaV1bal0gIT0gYykgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgaWYgKGMgPT0gJ0EnKSBkcFtpXVtqXSA9IDE7CiAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgayA9IDA7IGsgPCA4OyBrKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgaW50IHIgPSBpICsgZHhba10sIGMgPSBqICsgZHlba107CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChyID49IDAgJiYgYyA+PSAwICYmIHIgPCBSICYmIGMgPCBDICYmCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBWW3JdW2NdID09IFZbaV1bal0gLSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkcFtpXVtqXSA9IG1heChkcFtpXVtqXSwgZHBbcl1bY10gKyAxKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICByZXMgPSBtYXgocmVzLCBkcFtpXVtqXSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCAiQ2FzZSAiIDw8IGNzIDw8ICI6ICIgPDwgcmVzIDw8IGVuZGw7CiAgICB9Cn0=