#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = 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;
  vc<string> G(H);
  for (int i = 0; i < (H); i++) cin >> G[i];
  vl dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
  ll ans = 0;
  queue<pair<ll, ll>> q;
  vvc<ll> road(H, vc<ll>(W, INF));
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) {
      if (G[i][j] == '#') continue;
      vvc<ll> dist;
      dist = road;
      dist[i][j] = 0;
      q.emplace(i, j);
      while (!q.empty()) {
        ll x, y;
        tie(x, y) = q.front();
        q.pop();
        for (int d = 0; d < (4); d++) {
          ll nx = x + dx[d], ny = y + dy[d];
          if (nx < 0 || nx > H - 1 || ny < 0 || ny > W - 1) continue;
          if (G[nx][ny] == '#' || dist[nx][ny] <= dist[x][y]) continue;
          dist[nx][ny] = dist[x][y] + 1;
          q.emplace(nx, ny);
        }
      }
      ll tmp = 0;
      for (auto R : dist)
        for (auto r : R)
          if (r != INF) tmp = max(tmp, r);
      ans = max(ans, tmp);
    }
  cout << ans << endl;
  return 0;
}
