#include <bits/stdc++.h>
using namespace std;
char test[213][213];
long long usi[123], uiop[123];
signed main() {
  long long n, k, m, b = 0, c = 0, ans = 0;
  char a;
  cin >> n >> m;
  vector<vector<long long>> aa(n * m);
  for (long long h = 1; h <= n; h++) {
    for (long long i = 1; i <= m; i++) {
      cin >> a;
      test[h][i] = a;
      if (a == '.') {
        usi[b] = h;
        uiop[b] = i;
        b++;
      }
    }
  }
  for (long long h = 0; h < b - 1; h++) {
    for (long long i = h + 1; i < b; i++) {
      long long d[123][123], dx[4] = {1, 0, -1, 0}, dy[4] = {1, 0, -1, 0};
      queue<pair<long long, long long>> que;
      for (long long j = 1; j <= n; j++) {
        for (long long k = 1; k <= m; k++) {
          d[j][k] = 10000;
        }
      }
      que.push(pair<long long, long long>(usi[h], uiop[h]));
      d[usi[h]][uiop[h]] = 0;
      while (que.size()) {
        pair<long long, long long> p = que.front();
        que.pop();
        if (p.first == usi[i] && p.second == uiop[i]) {
          ans = max(ans, d[p.first][p.second]);
          break;
        }
        for (long long j = 0; j < 4; j++) {
          long long nx = p.first + dx[j], ny = p.second + dy[j];
          if (0 <= nx && nx < n && 0 <= ny && ny < m && test[nx][ny] != '#' &&
              d[nx][ny] == 10000) {
            que.push(pair<long long, long long>(nx, ny));
            d[nx][ny] = d[p.first][p.second] + 1;
            cout << d[nx][ny] << endl;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
