#include <bits/stdc++.h>
using namespace std;
queue<int> Q;
char a[22][22];
int h, w, visit[22][22], dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1};
void bfs(int sy, int sx) {
  int i, j;
  memset(visit, -1, sizeof(visit));
  Q.push(sy);
  Q.push(sx);
  visit[sy][sx] = 0;
  while (!Q.empty()) {
    int yy = Q.front();
    Q.pop();
    int xx = Q.front();
    Q.pop();
    for (i = 0; i < 4; i++) {
      int ty = yy + dy[i];
      int tx = xx + dx[i];
      if (ty >= 1 && ty <= h && tx >= 1 && tx <= w && a[ty][tx] == '.' &&
          visit[ty][tx] == -1) {
        Q.push(ty);
        Q.push(tx);
        visit[ty][tx] = visit[yy][xx] + 1;
      }
    }
  }
}
int main(void) {
  int i, j, k, l, ans = 0;
  scanf("%d %d", &h, &w);
  for (i = 1; i <= h; i++) scanf("%s", &a[i][1]);
  for (i = 1; i <= h; i++)
    for (j = 1; j <= w; j++) {
      bfs(i, j);
      int max = 0;
      for (k = 1; k <= h; k++)
        for (l = 1; l <= w; l++)
          if (max < visit[k][l]) max = visit[k][l];
      if (ans < max) ans = max;
    }
  printf("%d", ans);
  return 0;
}
