#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s;
    rep(i,h){
        string t;
        cin >> t;
        s.push_back(t);
    }

    vector<int> dx{1,-1,0,0};
    vector<int> dy{0,0,1,-1};
    int ans = 0;
    rep(i,h)rep(j,w){
        if(s[i][j]=='#') continue;
        vector<vector<int>> dist(h,vector<int>(w,INF));
        queue<P> que;
        que.push({i,j});
        dist[i][j] = 0;
        while(!que.empty()){
            int x = que.front().first;
            int y = que.front().end;
            rep(dir,4){
                int ix = x+dx[i], iy = y+dy[i];
                if(ix<0 || ix>=w || iy<0 || iy>=h) continue;
                if(s[iy][ix]=='#') continue;
                if(dist[iy][ix]!=INF) continue;
                dist[iy][ix] = dist[y][x]+1;
                que.push({ix,iy});
            }
        }
        rep(ii,h)rep(jj,w){
            if(dist[ii][jj]!=INF){
                ans = max(ans,dist[ii][jj]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}