#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;
void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main() {
  init();
  ll H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (H); i++) cin >> S[i];
  vector<vector<ll>> isok(H, vl(W, 0));
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) {
      if (S[i][j] == '#') isok[i][j] = 1;
    }
  ll ans = 0;
  vvl ok(H, vl(W));
  queue<tuple<ll, ll, ll>> q;
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) {
      if (S[i][j] == '#') continue;
      ok = isok;
      q.emplace(i, j, 0);
      while (!q.empty()) {
        ll h, w, c;
        tie(h, w, c) = q.front();
        q.pop();
        ans = max(ans, c);
        ok[h][w] = 1;
        if (h > 0 && ok[h - 1][w] == 0) q.emplace(h - 1, w, c + 1);
        if (h < H - 1 && ok[h + 1][w] == 0) q.emplace(h + 1, w, c + 1);
        if (w > 0 && ok[h][w - 1] == 0) q.emplace(h, w - 1, c + 1);
        if (w < W - 1 && ok[h][w + 1] == 0) q.emplace(h, w + 1, c + 1);
      }
    }
  cout << ans << endl;
  return 0;
}
