#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 20 + 5;
const int M = 400 + 5;
int n, m, k;
char s[N][N];
int a[N][N];
int g[M][M], dis[M][M];
bool ok(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m || s[x][y] == '#') return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = ++cnt;
  memset(g, 0x3f3f3f3f, sizeof(g));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') continue;
      int x = i + 1, y = j;
      int u = a[i][j], v = a[x][y];
      if (ok(x, y)) g[u][v] = g[v][u] = 1;
      x = i;
      y = j + 1;
      u = a[i][j], v = a[x][y];
      if (ok(x, y)) g[u][v] = g[v][u] = 1;
    }
  for (int k = 1; k <= cnt; k++)
    for (int i = 1; i <= cnt; i++)
      for (int j = 1; j <= cnt; j++)
        if (g[i][j] > g[i][k] + g[k][j])
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  int ans = 0;
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= cnt; j++)
      if (g[i][j] != 0x3f3f3f3f) ans = max(ans, g[i][j]);
  printf("%d\n", ans);
  return 0;
}
