#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[30][30];
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};
void solve() {
  long long ans = -1;
  for (long long sth = (long long)(1); sth <= (long long)(H); ++sth) {
    ;
    for (long long stw = (long long)(1); stw <= (long long)(W); ++stw) {
      if (!field[sth][stw]) continue;
      long long table[23][23];
      for (long long i = (long long)(0); i <= (long long)(22); ++i) {
        for (long long j = (long long)(0); j <= (long long)(22); ++j)
          table[i][j] = 0;
      }
      queue<pair<pii, long long>> q;
      q.push(make_pair((pii(sth, stw)), 0));
      while (q.size()) {
        auto q1 = q.front();
        q.pop();
        pii qq = q1.first;
        long long nowh = qq.first, noww = qq.second;
        table[nowh][noww]++;
        long long cnt = q1.second;
        ans = max(ans, cnt);
        for (long long i = (long long)(0); i <= (long long)(3); ++i) {
          long long nexth = nowh + dh[i];
          long long nextw = noww + dw[i];
          if (table[nexth][nextw]) {
            continue;
          }
          if ((nexth < 1) || (nextw < 1) || (nexth > H) || (nextw > W)) {
            continue;
          } else {
            if (field[nexth][nextw] == 1) {
              q.push(make_pair(pii(nexth, nextw), cnt + 1));
            } else {
              continue;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}
