#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};

int dist[21][21];
int H, W;
char S[21][21];
int res;

void clean(){
  rep(i,H){
    rep(j,W){
      dist[i][j]=INF;
    }
  }
  return;
}

int bfs(int xs,int ys, int xg, int yg){
  queue<P> que;
  clean();
  que.push(P(ys,xs));
  dist[ys][xs]=0;

  while(que.size()){
    P p = que.front(); que.pop();
    int x0 = p.second; int y0 = p.first;
    if(y0==yg && x0==xg) break;

    rep(i,4){
      int x = x0 + dx[i]; int y = y0 + dy[i];
      if(0<=x && x <= W-1 && 0<=y && y<=H-1){
        if(S[y][x]=='.' && dist[y][x]==INF) {
          que.push(P(y,x));
          dist[y][x] = dist[y0][x0]+1;
        }
      }
    }
  }
  return dist[yg][xg];
}

int main()
{
  cin >> H >> W;

  rep(i,H) cin >> S[i];

  res=0;
  rep(sy,H){
    rep(sx,W){
      if(S[sy][sx] == "#") continue;
      rep(gy, H){
        rep(gx, W){
          if(S[gy][gx] == "#") continue;
          clean();
          int num = bfs(sx,sy,gx,gy);
          if(num < INF) res = max(res, num);
          //printf("s(%d, %d) g(%d, %d): %d\n", sx, sy, gx, gy, num);           
          //print();                                                            
        }
      }
    }
  }

  cout << res << endl;
}
