#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846264;
const int mod = 1000000007;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int> > b(25, vector<int>(25, 0));
  for (int i = (0); i < (h); ++i) {
    string s;
    cin >> s;
    for (int j = (0); j < (w); ++j) {
      if (s[j] == '.') {
        b[i + 1][j + 1] = 1;
      }
    }
  }
  int ans = 0;
  for (int si = (1); si < (h + 1); ++si) {
    for (int sj = (1); sj < (w + 1); ++sj) {
      int mx = 0;
      vector<vector<int> > s(25, vector<int>(25, mod));
      queue<pair<int, int> > q;
      s[si][sj] = 0;
      q.push(make_pair(si, sj));
      while (q.size()) {
        auto pr = q.front();
        q.pop();
        int ni = pr.first;
        int nj = pr.second;
        int ns = s[ni][nj];
        for (int d = (0); d < (4); ++d) {
          int ii = ni + dx[d];
          int jj = nj + dy[d];
          if (b[ii][jj] && ns + 1 < s[ii][jj]) {
            s[ii][jj] = ns + 1;
            q.push(make_pair(ii, jj));
            ans = max(ans, ns + 1);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
