#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
ll h , w ;
bool inarea(ll x,ll y){
  return x >= 0 && y >= 0 && x < w && y < h ;
}

int main()
{
cin >> h >> w ;
vector<vector<char>> v(h, vector<char>(w,0) );
rep(i,h)rep(j,w)cin >> v[i][j];

rep(i,h)rep(j,w){
  if(v[i][j]=='#')continue;
  vector<vector<ll>> vv(h, vector<ll>(w,-1));
  queue<pair<ll,ll>> q;
  vv[i][j]=0;
  q.push(make_pair(i,j));
  while(!q.empty()){
    auto r=q.front();
    q.pop();
    ll y=r.first,x=r.second;
    ll xx[4]={0,1,0,-1};
    ll yy[4]={1,0,-1,0};
    rep(kk,4){
      if(inarea(x+xx[kk],y+yy[kk])&&v[y+yy[kk]][x+xx[kk]]=='.'&&vv[y+yy[kk]][x+xx[kk]]==-1){
        vv[y+yy[kk]][x+xx[kk]]=vv[y][x]+1;
        ans=max(ans,vv[y+yy[kk]][x+xx[kk]]);
        q.push(make_pair(y+yy[kk],x+xx[kk]));
      }
    }
  }
}
cout << ans << endl;
return 0;
}