#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pli = pair<long long, long long>;
using pdd = pair<double, double>;
using pld = pair<long double, long double>;
constexpr long long mod1 = 1e9 + 7;
int main() {
  int h, w, m = 0;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; ++i) cin >> v[i];
  vector<vector<int>> d(h * w, vector<int>(h * w, 0));
  for (int i = 0; i < h * w; ++i) {
    for (int j = 0; j < h * w; ++j) {
      if (i % w != w - 1 && v[i / w][i % w] == '.' &&
          v[i / w][i % w + 1] == '.') {
        d[i][i + 1] = 1;
        d[i + 1][i] = 1;
      }
      if (i / w != h - 1 && v[i / w][i % w] == '.' &&
          v[i / w + 1][i % w] == '.') {
        d[i][i + w] = 1;
        d[i + w][i] = 1;
      }
    }
  }
  for (int i = 0; i < h * w; ++i) {
    for (int j = 0; j < h * w; ++j) {
      for (int k = 0; k < h * w; ++k) {
        d[j][k] = min(d[j][i] + d[i][k], d[j][k]);
      }
    }
  }
  for (int i = 0; i < h * w; ++i) {
    for (int j = 0; j < h * w; ++j) {
      m = max(m, d[i][j]);
    }
  }
  cout << m << endl;
  return 0;
}
