#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;
queue<Corr> q;
vector<ll> y_vec = {0, 0, -1, +1};
vector<ll> x_vec = {-1, +1, 0, 0};
ll bfs() {
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    if (y == g_y && x == g_x) return 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 0;
}
int main() {
  cin >> N >> M;
  ll ans = 0;
  vec.resize(N);
  for (ll i = 0; i < N; ++i) cin >> vec[i];
  for (int i = 0; i < (int)(N); i++) {
    for (int j = 0; j < (int)(M); j++) {
      for (int l = N - 1; l >= 0; l--) {
        for (int m = M - 1; m >= 0; m--) {
          if (vec[i][j] == '.' && vec[l][m] == '.' && (i != l && j != m)) {
            s_y = i;
            s_x = j;
            g_y = l;
            g_x = m;
          } else {
            break;
          }
          Corr start = {s_y, s_x, 0};
          q.emplace(start);
          ans = max(bfs(), ans);
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
