#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> S(22, vector<char>(22));
int maze(int sh, int sw, int gh, int gw, vector<vector<char>> ss, int ct) {
  int i, j, x, y, ct1, ct2, ct3, ct4;
  vector<vector<char>> s(22, vector<char>(22));
  s = ss;
  ct1 = ct2 = ct3 = ct4 = 0x7fffffff;
  if ((sh == gh) && (sw == gw)) return ct;
  s[sh][sw] = '#';
  if (s[sh - 1][sw] == '.') ct1 = maze(sh - 1, sw, gh, gw, s, ct + 1);
  if (s[sh + 1][sw] == '.') ct2 = maze(sh + 1, sw, gh, gw, s, ct + 1);
  if (s[sh][sw - 1] == '.') ct3 = maze(sh, sw - 1, gh, gw, s, ct + 1);
  if (s[sh][sw + 1] == '.') ct4 = maze(sh, sw + 1, gh, gw, s, ct + 1);
  return min(min(ct1, ct2), min(ct3, ct4));
}
int main() {
  int h, w, i, j, k, n, m, x, y, sh, sw, gh, gw, ans = 0;
  cin >> h >> w;
  for (i = 1; i <= h; i++)
    for (j = 1; j <= w; j++) cin >> S[i][j];
  for (sh = 1; sh <= h; sh++)
    for (sw = 1; sw <= w; sw++)
      for (gh = 1; gh <= h; gh++)
        for (gw = 1; gw <= w; gw++) {
          if ((sh == gh) && (sw == gw)) continue;
          if (S[sh][sw] == '#') continue;
          if (S[gh][gw] == '#') continue;
          ans = max(ans, maze(sh, sw, gh, gw, S, 0));
        }
  cout << ans << endl;
}
