#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 up(int i, int j) {
  int u = (i - 2) * m + j;
  int now = (i - 1) * m + j;
  d[u][now] = d[now][u] = 1;
}
void down(int i, int j) {
  int dow = i * m + j;
  int now = (i - 1) * m + j;
  d[dow][now] = d[now][dow] = 1;
}
void left(int i, int j) {
  int now = (i - 1) * m + j;
  int l = (i - 1) * m + j - 1;
  d[l][now] = d[now][l] = 1;
}
void right(int i, int j) {
  int now = (i - 1) * m + j;
  int r = (i - 1) * m + j + 1;
  d[r][now] = d[now][r] = 1;
}
void budong(int i, int j) {
  int now = (i - 1) * m + j;
  d[now][now] = 0;
}
void add(int i, int j) {
  if (s[i][j] == '#') return;
  if (s[i - 1][j] == '.') up(i, j);
  if (s[i + 1][j] == '.') down(i, j);
  if (s[i][j + 1] == '.') left(i, j);
  if (s[i][j - 1] == '.') right(i, j);
  budong(i, j);
}
void floyd() {
  int ans = 0;
  for (int k = 1; k <= n * m; k++)
    for (int i = 1; i <= n * m; i++)
      for (int j = 1; j <= n * m; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  for (int i = 1; i <= n * m; i++)
    for (int j = 1; j <= n * m; j++)
      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;
}
