#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s[i];
  int ans = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (s[y][x] == '#') continue;
      vector<vector<bool>> checked(h, vector<bool>(w, false));
      queue<pair<int, int>> que;
      que.push(pair<int, int>(x, y));
      vector<vector<int>> cnt(h, vector<int>(w, 0));
      while (!que.empty()) {
        pair<int, int> point = que.front();
        que.pop();
        int xx = point.first;
        int yy = point.second;
        int cc = cnt[yy][xx];
        checked[yy][xx] = true;
        if (xx - 1 >= 0 && s[yy][xx - 1] == '.' && !checked[yy][xx - 1]) {
          que.push(pair<int, int>(xx - 1, yy));
          cnt[yy][xx - 1] = cc + 1;
        }
        if (xx + 1 <= w - 1 && s[yy][xx + 1] == '.' && !checked[yy][xx + 1]) {
          que.push(pair<int, int>(xx + 1, yy));
          cnt[yy][xx + 1] = cc + 1;
        }
        if (yy - 1 >= 0 && s[yy - 1][xx] == '.' && !checked[yy - 1][xx]) {
          que.push(pair<int, int>(xx, yy - 1));
          cnt[yy - 1][xx] = cc + 1;
        }
        if (yy + 1 <= h - 1 && s[yy + 1][xx] == '.' && !checked[yy + 1][xx]) {
          que.push(pair<int, int>(xx, yy + 1));
          cnt[yy + 1][xx] = cc + 1;
        }
        ans = max(ans, cc);
      }
    }
  }
  cout << ans << endl;
}
