#include <bits/stdc++.h> 
using namespace std; 
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{   
     ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
     long long int n,m,ans1=0,p;cin>>n>>m;
     vector<long long int >adj[n*m+1];
     string s[n];
     for (long long int i=0;i<n;i++) cin>>s[i];
     for (long long int i=1;i<=n;i++) {
         p=(i-1)*m;
         for (long long int j=1;j<=m;j++) {
             if (s[i-1][j-1]=='.') {
                 if (j<=m-1) {
                     if (s[i-1][j]=='.') {adj[p+j].push_back(p+j+1);adj[p+j+1].push_back(p+j);}
                 }
                 if (i<=n-1) {
                     if (s[i][j-1]=='.') {adj[p+j].push_back(p+m+j);adj[p+m+j].push_back(p+j);}
                 }
             }
         }
     }
 /*     for (long long int i=1;i<=n*m;i++) {
          cout<<i<<" ";
          for (long long int j=0;j<adj[i].size();j++) {
              cout<<adj[i][j]<<" ";
          }
          cout<<endl;
      }*/
      bool v[n*m+1]={0};
     for (long long int i=1;i<=n*m;i++) {
         long long int ans=0,k;
         for (long long int i1=1;i1<=n*m;i1++) v[i1]=0;
    queue<long long int>q,q1;
    q.push(i);q1.push(0);
    while (q.size()!=0) {
        k=q.front();
        v[k]=1;
        ans=q1.front();
        q.pop();q1.pop();
       // cout<<k<<ans<<endl;
       // cout<<ans<<endl;
        for (long long int i1=0;i1<adj[k].size();i1++) {
            if (v[adj[k][i1]]==1) continue;
            q.push(adj[k][i1]);
            q1.push(ans+1);
            
            
        }
    }
    
  //  cout<<"BHAU"<<ans<<endl;
   ans1=max(ans,ans1);
}
cout<<ans1<<endl;
}