#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define mp make_pair
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

const ll inf = (ll)1e9;
ll H,W,ans;
char S[20][20];
ll d[20][20];
ll sx,sy,nx,ny,x,y;
ll dx[4] = {1,0,-1,0},dy[4]={0,1,0,-1};
queue<P> que;

int main(void){
    cin >> H >> W;
    rep(i,H)rep(j,W)cin >> S[i][j];
    ans = 0;
    rep(i,H)rep(j,W){
        rep(k,H)rep(l,W)d[k][l]=inf;
        if(S[i][j]=='#')continue;
        sx = i; sy=j;
        d[sx][sy] = 0;
        que.push(mp(sx,sy));
        while(!que.empty()){
            P p = que.front();que.pop();
            x = p.first;y=p.second;
            rep(k,4){
                nx = x + dx[k];ny=y+dy[k];
                if(nx<0 || nx>=H || ny<0||ny>=W||d[nx][ny]!=inf||S[nx][ny]=='#')continue;
                d[nx][ny] = d[x][y] + 1;
                que.push(mp(nx,ny));
            }
        }
        
        rep(k,H)rep(l,W)if(d[k][l]!=inf)ans = max(ans,d[k][l]);
    }
    cout << ans << endl;
}
