#include <bits/stdc++.h>
using namespace std;

int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>>s(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cin>>s[i][j];
  }
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      vector<vector<int>>distance(h,vector<int>(w));
      vector<vector<bool>>a(h,vector<bool>(w));
      queue<int>q;
      q.push(i);
      q.push(j);
      if(s[i][j]=='#') break;
      else{
        while(!queue.empty()){
          int f=q.front();
          q.pop();
          int g=q.front();
          q.pop();
          if((f-1>=0 && ! a[f-1][g]) && s[f-1][g]=='.'){
            int c=distance[f][g]+1;
            ans=max(ans,c);
            distance[f-1][g]=c;
            a[f-1][g]=true;
            q.push(f-1);
            q.push(g);
            
          }
          if((f+1<=n-1 && ! a[f+1][g]) && s[f+1][j]=='.'){
            int c=distance[f][g]+1;
            ans=max(ans,c);
            distance[f+1][g]=c;
            a[f+1][g]=true;
            q.push(f+1);
            q.push(g);
          }
          if((g-1>=0 && ! a[f][g-1]) && s[f][g-1]=='.'){
            int c=distance[f][g]+1;
            ans=max(ans,c);
            distance[f][g-1]=c;
            a[f][g-1]=true;
            q.push(f);
            q.push(g-1);
          }
          if((g+1<=n-1 && ! a[f][g+1]) && s[f][g+1]=='.'){
            int c=distance[f][g]+1;
            ans=max(ans,c);
            distance[f][g+1]=c;
            a[f][g+1]=true;
            q.push(f);
            q.push(g+1);
          }
        }
      }
    }
    cout<<ans<<endl;
}