#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modpow(long long a, long long x) {
  if (a < 0) a += MOD;
  long long ans = 1;
  while (x > 0) {
    if (x & 1) ans = ans * a % MOD;
    a = a * a % MOD;
    x >>= 1;
  }
  return ans;
}
long long gyaku(long long n) { return modpow(n, MOD - 2); }
long long h, w;
char s[21][21];
vector<long long> a = {1, 0, -1, 0};
vector<long long> b = {0, 1, 0, -1};
long long dismax;
void dfs(long long sx, long long sy, vector<vector<long long>>& dis) {
  for (long long i = 0; i < (long long)(4); i++) {
    long long dx = a[i], dy = b[i];
    if (s[dx + sx][dy + sy] != '#' && dx + sx < h && dy + sy < w &&
        dx + sx >= 0 && dy + sy >= 0 &&
        (dis[dx + sx][dy + sy] > dis[sx][sy] + 1)) {
      dis[dx + sx][dy + sy] = dis[sx][sy] + 1;
      dfs(sx + dx, sy + dy, dis);
    }
  }
}
signed main() {
  cin >> h >> w;
  for (long long i = 0; i < (long long)(h); i++)
    for (long long j = 0; j < (long long)(w); j++) cin >> s[i][j];
  long long ans = 0;
  for (long long i = 0; i < (long long)(h); i++)
    for (long long j = 0; j < (long long)(w); j++) {
      long long sx = i, sy = j;
      if (s[sx][sy] == '#') break;
      dismax = 0;
      vector<vector<long long>> dis(h, vector<long long>(w, 1000000000000));
      dis[sx][sy] = 0;
      dfs(sx, sy, dis);
      for (long long ii = 0; ii < (long long)(h); ii++)
        for (long long jj = 0; jj < (long long)(w); jj++)
          if (dis[ii][jj] != 1000000000000) dismax = max(dismax, dis[ii][jj]);
      ans = max(ans, dismax);
    }
  cout << ans << endl;
}
