#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long SZ = 107;
const long long N = 1e6 + 7;
long long pwr(long long x, long long y) {
  long long r = 1LL;
  while (y) {
    if (y & 1) r = (r * x) % MOD;
    y >>= 1;
    x = (x * x) % MOD;
  }
  return r;
}
long long inv(long long x) { return pwr(x, MOD - 2ll); }
long long fact[N];
long long nCr(long long x, long long y) {
  long long ans = fact[x];
  ans *= inv(fact[y]);
  ans %= MOD;
  ans *= inv(fact[x - y]);
  ans %= MOD;
  return ans;
}
string a[21];
long long n, m;
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == '#') continue;
      long long d[n][m];
      bool vis[n][m];
      memset(vis, 0, sizeof vis);
      for (long long ii = 0; ii < n; ii++)
        for (long long jj = 0; jj < m; jj++) d[ii][jj] = 1e6;
      queue<pair<long long, long long> > q;
      q.push({i, j});
      d[i][j] = 0;
      while (!q.empty()) {
        pair<long long, long long> p = q.front();
        q.pop();
        long long x = p.first, y = p.second;
        ans = max(ans, d[x][y]);
        if (x - 1 >= 0 and !vis[x - 1][y] and a[x - 1][y] == '.') {
          vis[x - 1][y] = 1;
          d[x - 1][y] = 1 + d[x][y];
          q.push({x - 1, y});
        }
        if (x + 1 < n and !vis[x + 1][y] and a[x + 1][y] == '.') {
          vis[x + 1][y] = 1;
          d[x + 1][y] = 1 + d[x][y];
          q.push({x + 1, y});
        }
        if (y - 1 >= 0 and !vis[x][y - 1] and a[x][y - 1] == '.') {
          vis[x][y - 1] = 1;
          d[x][y - 1] = 1 + d[x][y];
          q.push({x, y - 1});
        }
        if (y + 1 < m and !vis[x][y + 1] and a[x][y + 1] == '.') {
          vis[x][y + 1] = 1;
          d[x][y + 1] = 1 + d[x][y];
          q.push({x, y + 1});
        }
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
