#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 2019;
ll modPow(ll a, ll n) {
  if (n == 0) return 1;
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  ll t = modPow(a, n / 2);
  return (t * t) % MOD;
}
int main() {
  int H, W, ans = 0;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (H); ++i) cin >> S.at(i);
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      if (S.at(i).at(j) == '#') {
        continue;
      }
      vector<vector<int>> dp(H, vector<int>(W, 1000));
      dp.at(i).at(j) = 0;
      queue<P> Q;
      Q.push(P(i, j));
      while (!Q.empty()) {
        P q = Q.front();
        Q.pop();
        if (q.first != 0) {
          if (S.at(q.first - 1).at(q.second) != '#' &&
              dp.at(q.first - 1).at(q.second) > dp.at(q.first).at(q.second)) {
            dp.at(q.first - 1).at(q.second) = dp.at(q.first).at(q.second) + 1;
            ans = max(ans, dp.at(q.first - 1).at(q.second));
            Q.push(P(q.first - 1, q.second));
          }
        }
        if (q.first != H - 1) {
          if (S.at(q.first + 1).at(q.second) != '#' &&
              dp.at(q.first + 1).at(q.second) > dp.at(q.first).at(q.second)) {
            dp.at(q.first + 1).at(q.second) = dp.at(q.first).at(q.second) + 1;
            ans = max(ans, dp.at(q.first + 1).at(q.second));
            Q.push(P(q.first + 1, q.second));
          }
        }
        if (q.second != 0) {
          if (S.at(q.first).at(q.second - 1) != '#' &&
              dp.at(q.first).at(q.second - 1) > dp.at(q.first).at(q.second)) {
            dp.at(q.first).at(q.second - 1) = dp.at(q.first).at(q.second) + 1;
            ans = max(ans, dp.at(q.first).at(q.second - 1));
            Q.push(P(q.first, q.second - 1));
          }
        }
        if (q.second != W - 1) {
          if (S.at(q.first).at(q.second + 1) != '#' &&
              dp.at(q.first).at(q.second + 1) > dp.at(q.first).at(q.second)) {
            dp.at(q.first).at(q.second + 1) = dp.at(q.first).at(q.second) + 1;
            ans = max(ans, dp.at(q.first).at(q.second + 1));
            Q.push(P(q.first, q.second + 1));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
