#include <bits/stdc++.h>

#define DEBUG(x) cerr << "DEBUG: " << x << "\n";
#define vv(x) vector<vector<x>>

using namespace std;

int h, w;

int dfs(const vv(char)& adj, vv(int)& visited, const pair<int, int>& cur_pos, int dist) {
        int i = cur_pos.first, j = cur_pos.second;
        char cur = adj[i][j];
        char target = (((cur - 'A') + 1) % 26) + 'A';
        //DEBUG("current data: " << x << y << cur)
        //DEBUG("target is: " << target)

        if(visited[i][j] != -1) return visited[i][j];

        // step in all directions
        vector<pair<int, int>> step;
        step.push_back(make_pair(i+1, j));
        step.push_back(make_pair(i+1, j+1));
        step.push_back(make_pair(i+1, j-1));
        step.push_back(make_pair(i, j+1));
        step.push_back(make_pair(i, j-1));
        step.push_back(make_pair(i-1, j));
        step.push_back(make_pair(i-1, j+1));
        step.push_back(make_pair(i-1, j-1));

        int max_dist = dist;
        for(const auto& pr: step) {
                int ni = pr.first, nj = pr.second;
                if(ni >= h || ni < 0) continue;
                if(nj >= w || nj < 0) continue;
                //DEBUG("current step: " << nx << ", " << ny)
                if(adj[ni][nj] == target) {
                        int new_dist = dfs(adj, visited, pr, dist+1);
                        max_dist = max(max_dist, new_dist);
                        //DEBUG("current dist: " << dist);
                }
        }
        visited[i][j] = max_dist;
        return max_dist;
}

int solve() {
        vector<vector<char>> adj (h, vector<char>(w));
        vector<vector<int>> dp (h, vector<int>(w, -1));
        //vector<vector<bool>> visited (h, vector<bool>(w));
        vector<pair<int, int>> start_pos;
        int d = 0, d_max = 0;
        char t;

        for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                        cin >> t;
                        adj[i][j] = t;
                        if(t == 'A') start_pos.push_back(make_pair(i, j));
                }
        }

        // reuse visited array
        for(const auto& pos: start_pos) {
                d = dfs(adj, dp, pos, d);
                d_max = max(d, d_max);
                d = 0;
        }

        if(start_pos.size())
                return d_max+1;  // include source
        else
                return 0;
}

int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        int num = 1;
        cin >> h >> w;
        do {
                int result = solve();
                cout << "Case " << num << ": " << result << "\n";
                num++;
                cin >> h >> w;
        } while(!(h == 0 && w == 0));

        return 0;
}
