#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; i++) cin >> v[i];
  int n = h * w;
  vector<vector<int>> d(n, vector<int>(n, 1e8));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i == j) d[i][i] = 0;
      if (v[i][j] == '#') continue;
      int ii = i + 1;
      int jj = j + 1;
      if (ii < h && v[ii][j] == '.') {
        d[i * w + j][ii * w + j] = 1;
        d[ii * w + j][i * w + j] = 1;
      }
      if (jj < w && v[i][jj] == '.') {
        d[i * w + j][i * w + jj] = 1;
        d[i * w + jj][i * w + j] = 1;
      }
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] == '#') continue;
      for (int ii = 0; ii < h; ii++) {
        for (int jj = 0; jj < w; jj++) {
          if (v[ii][jj] == '#') continue;
          ans = max(ans, d[i * w + j][ii * w + jj]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
