#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (long long i = 0; i < (H); i++) cin >> S[i];
  int ans = 0;
  for (long long i = 0; i < (H); i++)
    for (long long j = 0; j < (W); j++) {
      vector<vector<int> > X(H, vector<int>(W, -1));
      pair<int, int> st = make_pair(i, j);
      X[i][j] = 0;
      queue<pair<int, int> > Q;
      Q.push(st);
      while (!Q.empty()) {
        pair<int, int> now = Q.front();
        int x = now.first;
        int y = now.second;
        Q.pop();
        auto add = [&](int A, int B, int C, int D) {
          if (A + C < 0 or A + C > H - 1 or B + D < 0 or B + D > W - 1) return;
          if (S[A + C][B + D] == '#' or X[A + C][B + D] != -1) return;
          X[A + C][B + D] = X[A][B] + 1;
          Q.push(make_pair(A + C, B + D));
        };
        add(x, y, 0, 1);
        add(x, y, 0, -1);
        add(x, y, 1, 0);
        add(x, y, -1, 0);
      }
      int tmp = 0;
      for (long long i = 0; i < (H); i++)
        for (long long j = 0; j < (W); j++) tmp = max(tmp, X[i][j]);
      ans = max(ans, tmp);
    }
  cout << ans << endl;
}
