#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000001;
const int mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  int N = n * m;
  long long a[N][N];
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) a[i][j] = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.' && i + 1 < n && s[i + 1][j] == '.') {
        a[i * m + j][(i + 1) * m + j] = 1;
        a[(i + 1) * m + j][i * m + j] = 1;
      }
      if (s[i][j] == '.' && j + 1 < m && s[i][j + 1] == '.') {
        a[i * m + j][i * m + j + 1] = 1;
        a[i * m + j + 1][i * m + j] = 1;
      }
    }
  }
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (a[i][j] > a[i][k] + a[k][j]) {
          a[i][j] = a[i][k] + a[k][j];
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (a[i][j] != INT_MAX) ans = max(ans, a[i][j]);
    }
  }
  cout << ans << '\n';
}
