#include <bits/stdc++.h>
int GA[25][25], A[25][25], cnt, s[25][25] = {{0}};
void in(char c[25][25], int n, int m) {
  int move[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '#') continue;
      for (int k = 0; k < 4; k++) {
        int x = i + move[k][0];
        int y = j + move[k][1];
        if (x < 0 || x >= n || y < 0 || y >= m) continue;
        GA[s[i][j]][s[x][y]] = 1;
      }
    }
  }
}
void floyd() {
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= cnt; j++) A[i][j] = GA[i][j];
  for (int k = 1; k <= cnt; k++)
    for (int i = 1; i <= cnt; i++)
      for (int j = 1; j <= cnt; j++) {
        if (i == j || i == k || j == k) continue;
        if (A[i][k] + A[k][j] < A[i][j]) A[i][j] = A[i][k] + A[k][j];
      }
}
int main() {
  int n, m, max = -1;
  char c[25][25];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", c[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '#') continue;
      cnt++;
      s[i][j] = cnt;
    }
  for (int i = 0; i <= cnt; i++)
    for (int j = 0; j <= cnt; j++) GA[i][j] = 1000000007;
  in(c, n, m);
  floyd();
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= cnt; j++)
      if (A[i][j] != 1000000007 && A[i][j] > max) max = A[i][j];
  printf("%d", max);
  return 0;
}
