#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000;
long long powMod(long long x, long long n) {
  if (n == 0) return 1;
  long long r = powMod(x, n / 2);
  if (n % 2 == 0) return (r * r) % MOD;
  return (r * r % MOD) * x % MOD;
}
int main(void) {
  char s[30][30];
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < int(h); i++)
    for (int j = 0; j < int(w); j++) cin >> s[i][j];
  int z = 0;
  int num[30][30];
  for (int i = 0; i < int(h); i++)
    for (int j = 0; j < int(w); j++) {
      if (s[i][j] == '.')
        num[i][j] = z++;
      else
        num[i][j] = -1;
    }
  for (int i = 0; i < int(h); i++) {
    for (int j = 0; j < int(w); j++) {
      cout << num[i][j] << " ";
    }
    cout << endl;
  }
  int g[500][500] = {};
  for (int i = 0; i < int(z); i++)
    for (int j = 0; j < int(z); j++) g[i][j] = 100000000;
  for (int i = 0; i < int(z); i++) g[i][i] = 0;
  for (int i = 0; i < int(h); i++)
    for (int j = 0; j < int(w); j++) {
      for (int k = -1; k <= 1; k++) {
        for (int l = -1; l <= 1; l++) {
          if (0 <= i + k && i + k <= h - 1 && 0 <= j + l && j + l <= w - 1) {
            if (s[i][j] == '#' || s[i + k][j + l] == '#') continue;
            if (k * l != 0) continue;
            g[num[i][j]][num[i + k][j + l]] = 1;
            g[num[i + k][j + l]][num[i][j]] = 1;
          }
        }
      }
    }
  for (int k = 0; k < int(z); k++)
    for (int i = 0; i < int(z); i++)
      for (int j = 0; j < int(z); j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
  int ans = 0;
  for (int i = 0; i < int(z); i++)
    for (int j = 0; j < int(z); j++) ans = max(ans, g[i][j]);
  cout << ans << endl;
}
