#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>

int main(){
    ios::sync_with_stdio(0);
    int h, w, ans = 0;
    cin >> h >> w;
    string maze[h];
    for (int i = 0 ; i < h ; ++i)
        cin >> maze[i];
    for (int si = 0 ; si < h ; ++si){
        for (int sj = 0 ; sj < w ; ++sj){
            if (maze[si][sj] == '#')
                continue;
            for (int di = 0 ; di < h ; ++di){
                for (int dj = 0 ; dj < w ; ++dj){
                    if (maze[di][dj] == '#')
                        continue;
                    queue<pair<pii,int>> Q;
                    bool vis[h][w] = {false};
                    Q.push({{si,sj},0});
                    while(!Q.empty()){
                        int x = Q.front().first.first, y = Q.front().first.second, l = Q.front().second;
                        vis[x][y] = true;
                        Q.pop();
                        if (x == di && y == dj){
                            ans = max(ans, l);
                            break;
                        }
                        else{
                            int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
                            for (int i = 0 ; i < 4 ; ++i){
                                if (x+dx[i] >= 0 && x+dx[i] < h && y+dy[i] >= 0 && y+dy[i] < w && !vis[x+dx[i]][y+dy[i]] && maze[x+dx[i]][y+dy[i]] == '.')
                                    Q.push({{x+dx[i],y+dy[i]},l+1});
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}
