#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int H,W;
    cin>>H>>W;
    vector<string> S(H);
    REP(i,H) cin>>S[i];
    vector<vector<ll>> dist(H*W,vector<ll>(H*W,1LL<<50));
    int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    REP(i,H*W){
        if(S[i/W][i%W]=='#') continue;
        REP(j,4){
            int nx=i/W+dx[j],ny=i%W+dy[j];
            if(0<=nx&&nx<H&&0<=ny&&ny<W&&S[nx][ny]=='.'){
                dist[nx*W+ny][i]=dist[i][nx*W+ny]=1;
            }
        }
        dist[i][i]=0;
    }
    REP(k,H*W) REP(i,H*W) REP(j,H*W){
        if(dist[i][j]>dist[i][k]+dist[k][j]){
            dist[i][j]=dist[i][k]+dist[k][j];
        }
    }
    ll ans=0;
    REP(i,H*W) REP(j,H*W){
        if(S[i/W][i%W]=='.'&&S[j/W][j%W]=='.') ans=max(ans,dist[i][j]);
    }
    cout<<ans<<endl;
}
