#include <bits/stdc++.h>
using namespace std;
int d[22][22][22][22];
string a[22];
const int fx1[4] = {-1, 1, 0, 0};
const int fx2[4] = {0, 0, -1, 1};
signed main() {
  int n, m;
  cin >> n >> m;
  int ans = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') continue;
      queue<pair<int, int> > que;
      que.push(make_pair(i, j));
      while (que.size()) {
        pair<int, int> fr = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          if (fr.first + fx1[k] < n && fr.first + fx1[k] >= 0 &&
              fr.second + fx2[k] < m && fr.second + fx2[k] >= 0 &&
              d[i][j][fr.first + fx1[k]][fr.second + fx2[k]] == 0 &&
              a[fr.first + fx1[k]][fr.second + fx2[k]] == '.') {
            d[i][j][fr.first + fx1[k]][fr.second + fx2[k]] =
                d[i][j][fr.first][fr.second] + 1;
            ans = max(ans, d[i][j][fr.first + fx1[k]][fr.second + fx2[k]]);
            que.push(make_pair(fr.first + fx1[k], fr.second + fx2[k]));
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
