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

#define rep(i,n) for(int i{0};i<(int)n;++i)

signed main(){

  int h,w;
  scanf("%d %d",&h,&w);
  char s[30][30];
  scanf("%c",&s[0][0]);
  rep(i,h){
    rep(j,w){
      scanf("%c",&s[i][j]);
    }
    scanf("%c",&s[25][25]);
  }

  int ans = 0;
  rep(i,h)rep(j,w){
    if(s[i][j]=='#')continue;
    queue<tuple<int,int,int>> que;
    que.emplace(i,j,0);
    int dist[30][30];
    constexpr int inf = 1<<28;
    rep(k,h)rep(l,w)dist[k][l]=inf;
    while(!que.empty()){
      int y,x,c;
      tie(y,x,c) = que.front();
      que.pop();
      if(dist[y][x]>c){
        if(c>ans)ans=c;
        dist[y][x]=c;
        int ny{y},nx{x};
        ny--;
        if(ny!=-1&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
        ny+=2;
        if(ny!=h&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
        ny--;
        nx--;
        if(nx!=-1&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
        nx+=2;
        if(nx!=w&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
      }
    }
  }
  printf("%d",ans);

}