#include <bits/stdc++.h>
using namespace std;
int h, w;
int maze(int sh1, int sw1, vector<vector<char>> S) {
  int i, j, sh, sw;
  vector<vector<char>> s(h + 2, vector<char>(w + 2));
  s = S;
  s[sh1][sw1] = 0;
  i = 0;
  while (1) {
    j = 0;
    for (sh = 1; sh <= h; sh++)
      for (sw = 1; sw <= w; sw++) {
        if (s[sh][sw] == i) {
          if (s[sh - 1][sw] == '.') {
            s[sh - 1][sw] = i + 1;
            j = 1;
          }
          if (s[sh + 1][sw] == '.') {
            s[sh + 1][sw] = i + 1;
            j = 1;
          }
          if (s[sh][sw - 1] == '.') {
            s[sh][sw - 1] = i + 1;
            j = 1;
          }
          if (s[sh][sw + 1] == '.') {
            s[sh][sw + 1] = i + 1;
            j = 1;
          }
        }
      }
    if (j == 0) break;
    i++;
  }
  return i;
}
int main() {
  int i, j, k, n, m, x, y, sh, sw, gh, gw, ans = 0;
  cin >> h >> w;
  vector<vector<char>> S(h + 2, vector<char>(w + 2));
  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++) {
      if (S[sh][sw] == '#') continue;
      ans = max(ans, maze(sh, sw, S));
    }
  cout << ans << endl;
}
