#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (auto &s : S) cin >> s;
  int ans = 0;
  vector<int> xd = {0, 1, 0, -1};
  vector<int> yd = {1, 0, -1, 0};
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      vector<vector<int> > HW(H, vector<int>(W, -1));
      queue<pair<int, int> > que;
      que.push({i, j});
      HW[i][j] = 0;
      while (!que.empty()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        for (int i = 0; i < (int)(4); i++) {
          if (x + xd[i] > H - 1 || x + xd[i] < 0) continue;
          if (y + yd[i] > W - 1 || y + yd[i] < 0) continue;
          if (HW[x + xd[i]][y + yd[i]] != -1) continue;
          if (S[x + xd[i]][y + yd[i]] == '#') continue;
          que.push({x + xd[i], y + yd[i]});
          HW[x + xd[i]][y + yd[i]] = HW[x][y] + 1;
          ans = max(ans, HW[x + xd[i]][y + yd[i]]);
        }
      }
    }
  }
  cout << ans << endl;
}
