#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const vector<vector<int>> dir4 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> hen(h + 2, vector<bool>(w + 2));
    for(int i = 1; i <= h; i++)for(int j = 1; j <= w; j++){
        char tmp; cin >> tmp; hen[i][j] = tmp == '.';
    }
    int res = 0;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            for(int k = 1; k <= h; k++){
                for(int t = 1; t <= w; t++){

                    if(!hen[i][j] || !hen[k][t])continue;
                    vector<vector<int>> dist(h + 2, vector<int>(w + 2, -1));
                    queue<pair<int,int>> que;
                    dist[i][j] = 0;


                    que.push({i,j});
                    while(true) {
                        auto cur = que.front();
                        que.pop();
                        if(cur.first == k && cur.second == t){
                            res = max(res, dist[cur.first][cur.second]);
                            break;
                        }

                        for(int i = 0; i < 4; i++){
                            int y = cur.first + dir[i][0], x = cur.second + ddir[i][1];
                            if(!hen[y][x] || dist[y][x] != -1)continue;
                            dist[y][x] = dist[cur.first][cur.second] + 1;
                            que.push({y,x});
                        }
                    }


                }
            }
        }
    }


    cout << res << endl;

}