#include <bits/stdc++.h>
using namespace std;
long long H, W;
bool michi[22][22];
long long d[22][22][22][22];
void warshall_floyd() {
  for (long long mh = 1; mh <= H; mh++)
    for (long long mw = 1; mw <= W; mw++) {
      if (!michi[mh][mw]) continue;
      for (long long sh = 1; sh <= H; sh++)
        for (long long sw = 1; sw <= W; sw++) {
          if (!michi[sh][sw]) continue;
          for (long long eh = 1; eh <= H; eh++)
            for (long long ew = 1; ew <= W; ew++) {
              if (!michi[eh][ew]) continue;
              d[sh][sw][eh][ew] =
                  min(d[sh][sw][eh][ew], d[sh][sw][mh][mw] + d[mh][mw][eh][ew]);
            }
        }
    }
}
signed main() {
  cin >> H >> W;
  for (long long h = 1; h <= H; h++)
    for (long long w = 1; w <= W; w++) {
      char c;
      cin >> c;
      if (c == '.') michi[h][w] = true;
    }
  for (long long sh = 1; sh <= H; sh++)
    for (long long sw = 1; sw <= W; sw++) {
      for (long long eh = 1; eh <= H; eh++)
        for (long long ew = 1; ew <= W; ew++) {
          if (sh == eh && sw == ew) {
            d[sh][sw][eh][ew] = 0;
          } else if (!michi[sh][sw] || !michi[eh][ew]) {
            d[sh][sw][eh][ew] = 10;
          } else if (((long long)abs(sh - eh) == 1 &&
                      (long long)abs(sw - ew) == 0) ||
                     ((long long)abs(sh - eh) == 0 &&
                      (long long)abs(sw - ew) == 1)) {
            d[sh][sw][eh][ew] = 1;
          } else {
            d[sh][sw][eh][ew] = 10;
          }
        }
    }
  warshall_floyd();
  long long ans = 0;
  for (long long sh = 1; sh <= H; sh++)
    for (long long sw = 1; sw <= W; sw++) {
      for (long long eh = 1; eh <= H; eh++)
        for (long long ew = 1; ew <= W; ew++) {
          if (sh == eh && sw == ew) continue;
          if (!michi[sh][sw] || !michi[eh][ew]) continue;
          ans = max(ans, d[sh][sw][eh][ew]);
        }
    }
  cout << ans << endl;
}
