#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
using vi = vector<long long>;
const long long MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;
long long H, W;
string S;
vi va, vb;
long long field[24][24];
void input() {
  cin >> H >> W;
  for (long long i = (long long)(1); i <= (long long)(H); ++i) {
    ;
    ;
    for (long long j = (long long)(1); j <= (long long)(W); ++j) {
      char c;
      cin >> c;
      field[i][j] = (c == '#' ? 0 : 1);
      ;
    }
  };
  ;
}
long long dh[4] = {-1, 0, 0, 1};
long long dw[4] = {0, -1, 1, 0};
long long dp[23][23][23][23];
void solve() {
  for (long long h = (long long)(1); h <= (long long)(H); ++h) {
    for (long long w = (long long)(1); w <= (long long)(W); ++w) {
      queue<pii> q;
      if (field[h][w] == 0) {
        dp[h][w][h][w] = -1;
        continue;
      } else {
        dp[h][w][h][w] = 0;
        q.push(pii(h, w));
      }
      while (q.size()) {
        pii qq = q.front();
        q.pop();
        long long nh = qq.first, nw = qq.second;
        for (long long i = (long long)(0); i <= (long long)(3); ++i) {
          long long ph = nh + dh[i];
          long long pw = nw + dw[i];
          if (field[ph][pw] == 0) {
            dp[h][w][ph][pw] = -1;
            continue;
          }
          if (dp[h][w][ph][pw] > 0) {
            continue;
          }
          dp[h][w][ph][pw] = dp[h][w][nh][nw] + 1;
          q.push(pii(ph, pw));
        }
      }
    }
  }
  long long ans = -1;
  for (long long i = (long long)(1); i <= (long long)(H); ++i) {
    for (long long j = (long long)(1); j <= (long long)(W); ++j) {
      for (long long k = (long long)(1); k <= (long long)(H); ++k) {
        for (long long l = (long long)(1); l <= (long long)(W); ++l) {
          ans = max(ans, dp[i][j][k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}
