#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const int inf = 1e9 + 3;
const ll INF = 1e18 + 3;
const ld EPS = 1e-10;
template <typename T>
bool chmax(T &x, const T &y) {
  return (x < y) ? (x = y, true) : false;
};
template <typename T>
bool chmin(T &x, const T &y) {
  return (x > y) ? (x = y, true) : false;
};
int main() {
  int H, W;
  cin >> H >> W;
  string S[H + 2];
  S[0] = "";
  for (int i = 0; i < W + 2; i++) S[0] += '#';
  S[H + 1] = S[0];
  for (int i = 1; i <= H; i++) cin >> S[i];
  for (int i = 1; i <= H; i++) S[i] = '#' + S[i] + '#';
  int ans = 0;
  int d[H + 2][W + 2];
  for (int p = 1; p <= H; p++)
    for (int q = 1; q <= W; q++) {
      fill(d[0], d[H + 2], inf);
      d[p][q] = 0;
      queue<pii> que;
      que.push(pii(p, q));
      while (!que.empty()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        for (int i = -1; i <= 1; i++)
          for (int j = -1; j <= 1; j++) {
            if (i * j != 0 || i + j == 0) continue;
            if (S[x + i][y + j] == '#') continue;
            if (chmin(d[x + i][y + j], d[x][y] + 1)) {
              que.push(pii(x + i, y + j));
            }
          }
      }
      for (int x = 1; x <= H; x++)
        for (int y = 1; y <= W; y++) {
          if (d[x][y] != inf) chmax(ans, d[x][y]);
        }
    }
  cout << ans << endl;
}
