#include <bits/stdc++.h>
using namespace std;
int h, w, sh, sw, eh, ew, ans = 0, tans = 0;
void go(int pw, int ph, bool color[21][21], int cnt) {
  if (!(pw <= w && pw >= 1 && ph <= h && ph >= 1)) return;
  color[ph][pw] = false;
  bool c[21][21];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      c[i][j] = color[i][j];
    }
  }
  if (pw == ew && ph == eh) {
    cout << ph << pw << " " << cnt << endl;
    tans = min(tans, cnt);
    return;
  }
  if (c[ph + 1][pw]) {
    go(pw, ph + 1, c, cnt + 1);
  }
  if (c[ph - 1][pw]) {
    go(pw, ph - 1, c, cnt + 1);
  }
  if (c[ph][pw + 1]) {
    go(pw + 1, ph, c, cnt + 1);
  }
  if (c[ph][pw - 1]) {
    go(pw - 1, ph, c, cnt + 1);
  }
  return;
}
int main() {
  cin >> h >> w;
  char s[h + 1][w + 1];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
    }
  }
  bool color[21][21];
  for (int k = 1; k <= h; k++) {
    for (int l = 1; l <= w; l++) {
      if (s[k][l] == '.') {
        color[k][l] = true;
      } else {
        color[k][l] = false;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= h; i++) color[i][0] = false;
  for (int i = 0; i <= w; i++) color[0][i] = false;
  for (int i = 1; i <= h * w; i++) {
    for (int j = 1; j <= h * w; j++) {
      if (i == j) continue;
      sw = i % w == 0 ? w : i % w;
      sh = ceil(i / float(w));
      ew = j % w == 0 ? w : j % w;
      eh = ceil(j / float(w));
      for (int k = 0; k <= h; k++) {
        for (int l = 0; l <= w; l++) {
          if (s[k][l] == '.') {
            color[k][l] = true;
          } else {
            color[k][l] = false;
          }
        }
      }
      if (!color[sh][sw] || !color[eh][ew]) continue;
      tans = 100000000;
      go(sw, sh, color, 0);
      ans = max(ans, tans);
    }
  }
  cout << ans << endl;
  return 0;
}
