#include <bits/stdc++.h>
using namespace std;
bool compare(pair<long long int, long long int> a,
             pair<long long int, long long int> b) {
  return a.first * b.second < a.second * b.first;
}
const int mod = 1e9 + 7;
const long long int inf = long long int(1e18);
long long int modexp(long long int x, long long int n) {
  if (n == 0) return 1;
  if (n % 2 == 0) return modexp((x * x) % mod, n / 2);
  return (x * modexp((x * x) % mod, n / 2)) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  string s;
  cin >> h >> w;
  vector<vector<int> > a(h, vector<int>(w, 0));
  vector<vector<int> > b(h, vector<int>(w, 0));
  int c = 0;
  for (int i = 0; i < h; ++i) {
    cin >> s;
    for (int j = 0; j < w; ++j) {
      ++c;
      b[i][j] = c;
      if (s[j] == '.') a[i][j] = 1;
    }
  }
  int n = h * w;
  int ans = 0;
  vector<vector<int> > d(n + 1, vector<int>(n + 1, 1e9));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j] == 0) continue;
      if (i > 0 and a[i - 1][j] == 1) {
        d[b[i][j]][b[i - 1][j]] = 1;
      }
      if (i < h - 1 and a[i + 1][j] == 1) {
        d[b[i][j]][b[i + 1][j]] = 1;
      }
      if (j > 0 and a[i][j - 1] == 1) {
        d[b[i][j]][b[i][j - 1]] = 1;
      }
      if (j < w and a[i][j + 1] == 1) {
        d[b[i][j]][b[i][j + 1]] = 1;
      }
    }
  }
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  for (int i = 1; i < n + 1; ++i) {
    for (int j = 1; j < n + 1; ++j) {
      if (d[i][j] == 1e9) continue;
      ans = max(ans, d[i][j]);
    }
  }
  cout << ans << "\n";
}
