#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 2e5 + 5;
long long gcd(long long n, long long m) {
  if (n == 0)
    return m;
  else {
    return gcd(m % n, n);
  }
}
long long vis[30][30];
long long dp[30][30][30][30];
long long n, m;
char s[22][22];
long long go(long long i, long long j, long long pi, long long pj) {
  if (i <= 0 || i > n || j <= 0 || j > m) {
    return MOD;
  }
  if (i == pi && j == pj) return 0;
  if (s[i][j] == '#') return MOD;
  if (vis[i][j]) return MOD;
  long long ans = MOD;
  vis[i][j] = 1;
  ans = min(ans, 1 + go(i, j + 1, pi, pj));
  ans = min(ans, 1 + go(i, j - 1, pi, pj));
  ans = min(ans, 1 + go(i + 1, j, pi, pj));
  ans = min(ans, 1 + go(i - 1, j, pi, pj));
  vis[i][j] = 0;
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<pair<long long, long long> > vp;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> s[i][j];
      if (s[i][j] == '.') vp.push_back({i, j});
    }
  }
  memset(dp, -1, sizeof(dp));
  long long mx = 0;
  for (long long i = 0; i < vp.size(); i++) {
    for (long long j = 0; j < vp.size(); j++) {
      if (i != j) {
        long long k = go(vp[i].first, vp[i].second, vp[j].first, vp[j].second);
        if (k < MOD) mx = max(mx, k);
      }
    }
  }
  cout << mx << endl;
}
