#include <bits/stdc++.h>
using namespace std;
using Graph_c = vector<vector<char>>;
using ll=long long;
// 幅優先探索
struct Z{
  ll y;
  ll x;
  ll depth;
};

ll H,W,y,x,depth;
vector<ll> y_vec={1,0,-1,0};
vector<ll> x_vec={0,1,0,-1};
Graph_c A,B;
queue<Z> q;

ll bfs(){
  while(!q.empty()){
    Z now=q.front(); q.pop();
    y=now.y, x=now.x, depth=now.depth;
    for(ll i=0; i<4; i++){
      Z next={y+y_vec[i], x+x_vec[i], depth+1};
      if(A[next.y][next.x]=='.'){
        A[next.y][next.x]='#';
        q.push(next);
      }
    }
  }
  return depth;
}

int main(){
  cin>>H>>W;
  A.assign(H+2, vector<char>(W+2, '#'));
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      char a; cin>>a;
      A[i][j]=a;
    }
  }
  B=A;
  ll ans=0;
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(A[i][j]=='#') continue;
      A[i][j]='#';
      Z start={i,j,0};
      q.emplace(start);
      ans=max(ans,bfs());
      A=B;
    }
  }
  cout<<ans<<endl;
}