#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll INF = 1ll << 60;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = (int)(0); i < (int)(H); i++) cin >> S[i];
  vector<vector<bool>> wall(H, vector<bool>(W, false));
  for (int h = (int)(0); h < (int)(H); h++) {
    for (int w = (int)(0); w < (int)(W); w++) {
      if (S[h][w] == '#') wall[h][w] = true;
    }
  }
  int ans = 0;
  for (int sh = (int)(0); sh < (int)(H); sh++) {
    for (int sw = (int)(0); sw < (int)(W); sw++) {
      if (wall[sh][sw]) continue;
      queue<pair<int, int>> que;
      que.push(make_pair(sh, sw));
      vector<vector<bool>> check = wall;
      vvi di(H, vector<int>(W, -1));
      di[sh][sw] = 0;
      while (que.size() > 0) {
        int h = que.front().first, w = que.front().second;
        que.pop();
        check[h][w] = true;
        if (h > 0 && !(check[h - 1][w])) {
          di[h - 1][w] = di[h][w] + 1;
          que.push(make_pair(h - 1, w));
        }
        if (h < H - 1 && !(check[h + 1][w])) {
          di[h + 1][w] = di[h][w] + 1;
          que.push(make_pair(h + 1, w));
        }
        if (w > 0 && !(check[h][w - 1])) {
          di[h][w - 1] = di[h][w] + 1;
          que.push(make_pair(h, w - 1));
        }
        if (w < W - 1 && !(check[h][w + 1])) {
          di[h][w + 1] = di[h][w] + 1;
          que.push(make_pair(h, w + 1));
        }
      }
      int mx = di[0][0];
      for (int h = (int)(0); h < (int)(H); h++) {
        for (int w = (int)(0); w < (int)(W); w++) {
          mx = max(mx, di[h][w]);
        }
      }
      ans = max(ans, mx);
    }
  }
  cout << ans << endl;
  return 0;
}
