#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> x={0,1,0,-1},y={1,0,-1,0};
  int H,W;
  cin>>H>>W;
  vector<string> A(H+2,"");
  for(int i=0;i<W+2;i++){
    A[0]+="#";
    A[H+1]+="#";
  }
  for(int i=1;i<=H;i++){
    string S;
    cin>>S;
    A[i]="#"+S+"#";
  }
  int l=0;
  for(int i=1;i<=H;i++)
    for(int j=1;j<=W;j++)
      if(A[i][j]=='.'){
        queue<pair<int,int>> B;
        B.push(make_pair(i,j));
        vector<vector<int>> C(H+2,vector<int>(W+2,-1));
        C[i][j]=0;
        int k=0;
        while(true){
          int xx=B.front().first,yy=B.front().second;
          B.pop();
          for(int i=0;i<4;i++)
            if(A[xx+x[i]][yy+y[i]]=='.' && C[xx+x[i]][yy+y[i]]==-1){
              C[xx+x[i]][yy+y[i]]=C[xx][yy]+1;
              k=max(k,C[xx][yy]+1);
              B.push(make_pair(xx+x[i],yy+y[i]));
            }
          if(B.empty())
            break;
        }
        l=max(k,l);
      }
  cout<<l<<endl;
}