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

int main() { 
    int h, w, ans = 0;
    cin >> h >> w;
    int hw[h+2][w+2] = {0};
    char s;

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> s;
            if(s == '.') hw[i+1][j+1] = 1;
            else hw[i+1][j+1] = -1;
        }
    }

    for(int sh = 1; sh <= h; ++sh) {
        for(int sw = 1; sw <= w; ++sw) {
            for(int gh = 1; gh <= h; ++gh) {
                for(int gw = 1; gw <= w; ++gw) {
                    if(hw[sh][sw] == 1) {
                        queue<pair<pair<int, int>, int>> q;
                        q.push(make_pair(make_pair(sh, sw), 0));
                        int check[h+2][w+2] = {0};
                        while(q.size()) {
                            auto ijc = q.front();
                            q.pop();
                            int i = ijc.first.first, j = ijc.first.second, c = ijc.second;
                            
                            ans = max(ans, c);
                            if(i == gh && j == gw) break;

                            check[i][j] = 1;
                            if(hw[i-1][j] == 1 && check[i-1][j] == 0) {
                                q.push(make_pair(make_pair(i-1, j), c+1));
                            }
                            if(hw[i+1][j] == 1 && check[i+1][j] == 0) {
                                q.push(make_pair(make_pair(i+1, j), c+1));
                            }
                            if(hw[i][j-1] == 1 && check[i][j-1] == 0) {
                                q.push(make_pair(make_pair(i, j-1), c+1));
                            }
                            if(hw[i][j+1] == 1 && check[i][j+1] == 0) {
                                q.push(make_pair(make_pair(i, j+1), c+1));
                            }
                        }
                    }
                }
            }
        }
    }
    
    cout << ans << '\n';

    return 0;
}
