#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int H, W, ans; char S[25][25];
int bfs(int sy, int sx) {
  int y, x, dpp, d[25][25] = {}, t[25][25] = {};
  queue<P> q; q.push({sy, sx}); t[sy][sx] = 1;
  while(!q.empty()) {
    P p = q.front(); q.pop();
    y = p.first, x = p.second, dpp = d[y][x]+1;
    if(!t[y+1][x] && S[y+1][x] == '.') q.push({y+1, x}), d[y+1][x]=dpp, t[y+1][x]=1;
    if(!t[y-1][x] && S[y-1][x] == '.') q.push({y-1, x}), d[y-1][x]=dpp, t[y-1][x]=1;
    if(!t[y][x+1] && S[y][x+1] == '.') q.push({y, x+1}), d[y][x+1]=dpp, t[y][x+1]=1;
    if(!t[y][x-1] && S[y][x-1] == '.') q.push({y, x-1}), d[y][x-1]=dpp, t[y][x-1]=1;
  }
  return d[y][x];
}
int main() {
  scanf("%d %d\n", &H, &W);
  for(int i = 1; i <= H; ++i) scanf("%s\n", &S[i][1]);
  for(int y = 1; y <= H; ++y) {
    for(int x = 1; x <= W; ++x) {
      if(S[y][x] == '#') continue;
      ans = max(bfs(y, x), ans);
    }
  }
  printf("%d\n", ans);
}