#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1000000007;
const int64_t LINF = 1e13;
const int64_t LLINF = 1e18;
const int64_t ALPHABET = 26;
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
int main() {
  int64_t h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w, -1));
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  cerr << endl;
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      cerr << s[i][j];
    }
    cerr << endl;
  }
  cerr << endl;
  int64_t f = h * w;
  vector<vector<int64_t>> wdist(f * 2, vector<int64_t>(f * 2, LLINF));
  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      wdist[i * h + j][i * h + j] = 0;
    }
  }
  for (int64_t i = 0; i < f; ++i) {
    for (int64_t j = 0; j < f; j++) {
      for (int64_t k = 0; k < f; k++) {
        wdist[j][k] = min(wdist[j][k], wdist[j][i] + wdist[i][k]);
      }
    }
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < f; ++i) {
    for (int64_t j = 0; j < f; j++) {
      if (wdist[i][j] == LLINF) continue;
      ans = max(ans, wdist[i][j]);
    }
  }
  cout << ans << endl;
}
