#include <bits/stdc++.h>
using namespace std;
int h, w, a[23][23][23][23];
bool b[23][23];
int r(int i, int j, int k, int p) {
  if ((!b[i][j]) or (!b[k][p])) return 0;
  if (a[i][j][k][p]) return a[i][j][k][p];
  b[i][j] = 0;
  int mi = 1e5, t;
  if (t = r(i - 1, j, k, p)) mi = min(t, mi);
  if (t = r(i + 1, j, k, p)) mi = min(t, mi);
  if (t = r(i, j - 1, k, p)) mi = min(t, mi);
  if (t = r(i, j + 1, k, p)) mi = min(t, mi);
  b[i][j] = 1;
  if (mi == 1e5) return 0;
  return a[i][j][k][p] = mi + 1;
}
int main() {
  cin >> h >> w;
  int i, j, k, p;
  char x;
  memset(b, 0, sizeof(b));
  memset(a, 0, sizeof(a));
  for (i = 1; i <= h; ++i) {
    for (j = 1; j <= w; ++j) {
      cin >> x;
      if (x == '.') b[i][j] = 1;
    }
  }
  for (i = 1; i <= h; ++i) {
    for (j = 1; j <= w; ++j) {
      a[i][j][i + 1][j] = b[i + 1][j];
      a[i][j][i - 1][j] = b[i - 1][j];
      a[i][j][i][j + 1] = b[i][j + 1];
      a[i][j][i][j - 1] = b[i][j - 1];
    }
  }
  int ma = 0;
  for (i = 1; i <= h; ++i) {
    for (j = 1; j <= w; ++j) {
      for (k = 1; k <= h; ++k) {
        for (p = 1; p <= w; ++p) {
          ma = max(ma, r(i, j, k, p));
        }
      }
    }
  }
  cout << ma;
  return 0;
}
