#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

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){
      vector<vector<int>> dist(h,vector<int>(w,-1));
      queue<pair<int,int>> que;		
      
      if(s[i][j] == '#') continue;
      dist[i][j] = 0;
      que.push({i,j});
      
      while(!que.empty()){
        int u = que.front().first; 
        int v = que.front().second;
        que.pop();
        
        rep(k,4){
          int nu = u + dx[k]; 
          int nv = v + dy[k];
          if(nu<0||nu>=h||nv<0||nv>=w) continue;
          if(s[nu][nv] == '#') continue;
          if(dist[nu][nv] != -1) continue;
          que.push({nu,nv});
          dist[nu][nv] = dist[u][v] + 1;
          ans = max(ans,dist[nu][nv]);
        }
      }
    }
  }
  cout << ans << endl;
}