#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long h, w;
    cin >> h >> w;
    vector<string> v(h);
    for (long long int i = 0; i < h; i++) cin >> v[i];
    long long d = 0;
    long long n = h * w;
    long long dis[h * w + 1][h * w + 1];
    for (long long int i = 0; i < n + 1; i++) {
      for (long long int j = 0; j < n + 1; j++) dis[i][j] = 1000000007;
    }
    for (long long int i = 0; i < h; i++) {
      for (long long int j = 0; j < w; j++) {
        if (v[i][j] == '.') {
          if (i + 1 < h && v[i + 1][j] == '.') {
            long long f1 = w * i + j + 1;
            long long f2 = w * (i + 1) + j + 1;
            dis[f1][f2] = 1;
            dis[f2][f1] = 1;
          }
          if (j + 1 < w && v[i][j + 1] == '.') {
            long long f1 = w * i + j + 1;
            long long f2 = w * i + j + 2;
            dis[f1][f2] = 1;
            dis[f2][f1] = 1;
          }
        }
      }
    }
    long long ans = 0;
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
        }
      }
    }
    for (long long int i = 1; i < n + 1; i++)
      for (long long int j = 1; j < n + 1; j++) {
        if (dis[i][j] < 1000000007) {
          ans = max(ans, dis[i][j]);
        }
      }
    cout << ans << '\n';
  }
  return 0;
}
