#include <bits/stdc++.h>
int h, w;
char s[20][21];
int cnt[20][20];
int bfs(int y, int x) {
  cnt[y][x] = 0;
  const int dir[] = {0, -1, 0, 1, 0};
  using p = std::pair<int, int>;
  std::queue<p> q;
  q.push({y, x});
  while (q.size() > 0) {
    p a = q.front();
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int Y = a.first + dir[i];
      int X = a.second + dir[i + 1];
      if (0 <= X && X < w && 0 <= Y && Y < h && s[Y][X] == '.' &&
          cnt[Y][X] == -1) {
        q.push({Y, X});
        cnt[Y][X] = cnt[a.first][a.second] + 1;
      }
    }
  }
}
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i) {
    scanf("%s", s[i]);
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      for (int k = 0; k < h; ++k) {
        std::fill(cnt[k], cnt[k] + w, -1);
      }
      bfs(i, j);
      int max = 0;
      for (int a = 0; a < h; ++a) {
        for (int b = 0; b < w; ++b) {
          if (max < cnt[a][b]) max = cnt[a][b];
        }
      }
      if (ans < max) ans = max;
    }
  }
  printf("%d\n", ans);
}
