#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
const int p[]={-1,0,1,0};
const int v[]={0,-1,0,1};

int main(){
  int h,w; cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  int ans=0;
  
  rep(i,h)rep(j,w){
      if(s[i][j]=='#') continue;
      vector<vector<int>> d(h,vector<int>(w,-1));
      queue<P> wa;

      auto kyu=[&](int a, int b, int x){
          if(d[a][b]!='-1') return;
          d[a][b] = x;
          wa.push(P(a,b));
      };
      
      kyu(i,j,0);
      while(!wa.empty()){
          int nowi=wa.front().first;
          int nowj=wa.front().second;
          wa.pop();
         rep(dir,4){
             int ni=nowi+p[dir]; int nj=nowj+v[dir];
             if(ni<0||ni>=h||nj<0||nj>=w) continue;
             if(s[ni][nj]=='#') continue;
             if(d[ni][nj]==-1) continue;
             kyu(ni,nj,d[nowi][nowj]+1)
         }
      }
    rep(aa,h)rep(bb,w){
        ans=max(ans,d[aa][bb]);
    }
  }
  cout << ans << endl;
 return 0;
}
