#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (int)(h); i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int si = 0; si < (int)(h); si++) {
    for (int sj = 0; sj < (int)(w); sj++) {
      if (s[si][si] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      queue<pair<int, int>> q;
      auto update = [&](int i, int j, int x) {
        if (dist[i][j] != INF) return;
        dist[i][j] = x;
        q.push(pair<int, int>(i, j));
      };
      update(si, sj, 0);
      while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        for (int dir = 0; dir < (int)(4); dir++) {
          int ni = i + di[dir], nj = j + dj[dir];
          if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          if (s[ni][nj] == '#') continue;
          update(ni, nj, dist[i][j] + 1);
        }
      }
      for (int i = 0; i < (int)(h); i++) {
        for (int j = 0; j < (int)(w); j++) {
          if (dist[i][j] == INF) continue;
          ans = max(ans, dist[i][j]);
        }
      }
    }
  }
  cout << ans << endl;
  return;
}
int main() {
  solve();
  return 0;
}
