#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, ans, q[101010][2], bok[1010][1010];
int f[1010], ma[1010], fir[101010], nxt[202020], to[202020];
int fl[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
char s[1010][1010];
void add(int x, int y) {
  nxt[++cnt] = fir[x];
  fir[x] = cnt;
  to[cnt] = y;
}
void dfs(int x, int fa) {
  ma[x] = f[x] = 1;
  for (int i = fir[x]; i; i = nxt[i])
    if (to[i] != fa) {
      dfs(to[i], x);
      f[x] = max(f[x], max(f[to[i]], ma[to[i]] + ma[x]));
      ma[x] = max(ma[x], ma[to[i]] + 1);
    }
}
int id(int x, int y) { return (x - 1) * m + y; }
void bfs(int x, int y) {
  int fr = 0, b = 0;
  q[++b][0] = x;
  q[b][1] = y;
  bok[x][y] = 1;
  while (fr < b) {
    x = q[++fr][0], y = q[fr][1];
    for (int i = 0; i <= 3; i++) {
      int xx = x + fl[i][0], yy = y + fl[i][1];
      if (xx < 1 || xx > n || yy < 1 || yy > m || bok[xx][yy] ||
          s[xx][yy] == '#')
        continue;
      q[++b][0] = xx;
      q[b][1] = yy;
      bok[xx][yy] = 1;
      add(id(xx, yy), id(x, y));
      add(id(x, y), id(xx, yy));
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!bok[i][j] && s[i][j] == '.') {
        bfs(i, j);
        dfs(id(i, j), 0);
        ans = max(ans, f[id(i, j)]);
      }
  printf("%d\n", ans - 1);
  return 0;
}
