#include <bits/stdc++.h>
using namespace std;

int main(){
    int h, w, dot = 0, ans = 0;
    cin >> h >> w;
    char s[h][w];
    for(int i = 0; i < h; i++) cin >> s[i];

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '.') dot++;
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '.'){
                typedef pair<int, int> pair;
                int dt = dot - 1;
                int num = 0;
                vector<pair> xy;
                xy.push_back(make_pair(i, j));
                bool flag[h][w] = {};
                flag[i][j] = true;
                while(dt > 0){
                    num++;
                    stack<pair> xy2;
                    for(auto& it : xy){
                        int x = it.first;
                        int y = it.second - 1;
                        if(s[x][y] == '.' && !flag[x][y]){
                            flag[x][y] = true;
                            xy2.push(make_pair(x, y));
                            dt--;
                        }
                        y = it.second + 1;
                        if(s[x][y] == '.' && !flag[x][y]){
                            flag[x][y] = true;
                            xy2.push(make_pair(x, y));
                            dt--;
                        }
                        x = it.first - 1;
                        y = it.second;
                        if(s[x][y] == '.' && !flag[x][y]){
                            flag[x][y] = true;
                            xy2.push(make_pair(x, y));
                            dt--;
                        }
                        x = it.first + 1;
                        if(s[x][y] == '.' && !flag[x][y]){
                            flag[x][y] = true;
                            xy2.push(make_pair(x, y));
                            dt--;
                        }
                    }
                    xy.clear();
                    while(!xy2.empty()){
                        xy.push_back(make_pair(xy2.top().first, xy2.top().second));
                        xy2.pop();
                    }
                }
                if(ans < num) ans = num;
            }
        }
    }

    cout << ans << endl;
    return 0;
}