#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int inf = 0x3f3f3f3f;
int n, m;
char s[25][25];
int d[405][405];
void add(int i, int j) {
  if (s[i][j] == '#') return;
  if (s[i - 1][j] == '.')
    d[(i - 1) * m + j][(i - 2) * m + j] = d[(i - 2) * m + j][(i - 1) * m + j] =
        1;
  if (s[i + 1][j] == '.')
    d[(i - 1) * m + j][i * m + j] = d[i * m + j][(i - 1) * m + j] = 1;
  if (s[i][j + 1] == '.')
    d[(i - 1) * m + j][(i - 1) * m + j + 1] =
        d[(i - 1) * m + j + 1][(i - 1) * m + j] = 1;
  if (s[i][j - 1] == '.')
    d[(i - 1) * m + j - 1][(i - 1) * m + j] =
        d[(i - 1) * m + j][(i - 1) * m + j - 1] = 1;
  d[(i - 1) * m + j][(i - 1) * m + j] = 0;
}
void floyd() {
  int ans = 0;
  for (int p = 1; p <= n; p++)
    for (int q = 1; q <= m; q++)
      for (int y = 1; y <= n; y++)
        for (int t = 1; t <= m; t++)
          for (int l = 1; l <= n; l++)
            for (int r = 1; r <= m; r++) {
              if (s[p][q] == '#' || s[y][t] == '#' || s[l][r] == '#') continue;
              int i = (p - 1) * m + q;
              int j = (y - 1) * m + t;
              int k = (l - 1) * m + r;
              if (d[i][k] != inf && d[k][j] != inf)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]),
                d[j][i] = min(d[j][i], d[i][k] + d[k][j]);
            }
  for (int p = 1; p <= n; p++)
    for (int q = 1; q <= m; q++)
      for (int y = 1; y <= n; y++)
        for (int t = 1; t <= m; t++) {
          if (s[p][q] == '#' || s[y][t] == '#') continue;
          int i = (p - 1) * m + q;
          int j = (y - 1) * m + t;
          if (d[i][j] != inf) ans = max(ans, d[i][j]);
        }
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  memset(d, inf, sizeof(d));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) add(i, j);
  floyd();
  return 0;
}
