#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Corr {
  ll y;
  ll x;
  ll depth;
};
ll N, M;
ll s_y, s_x, g_y, g_x;
ll y, x, depth;
vector<string> vec;
vector<string> vv;
queue<Corr> q;
vector<ll> y_vec = {0, 0, -1, +1};
vector<ll> x_vec = {-1, +1, 0, 0};
ll bfs() {
  ll ret = 0;
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    ret = max(ret, depth);
    for (ll i = 0; i < 4; ++i) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (0 <= next.y && next.y <= N - 1 && 0 <= next.x && next.x <= M - 1 &&
          vec[next.y][next.x] == '.') {
        vec[next.y][next.x] = 'x';
        q.push(next);
      }
    }
  }
  return ret;
}
int main() {
  ll ans = 0;
  cin >> N >> M;
  vv.resize(N);
  vec.resize(N);
  for (ll i = 0; i < N; ++i) cin >> vv[i];
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < M; j++) {
      if (vv[i][j] == '.') {
        s_y = i, s_x = j;
        for (ll k = 0; k < N; k++) vec[k] = vv[k];
        Corr start = {s_y, s_x, 0};
        q.emplace(start);
        ans = max(bfs(), ans);
      }
    }
  }
  cout << ans << "\n";
}
