#include <bits/stdc++.h>
using namespace std;
const long long LLINF = (1LL << 60);
const long long INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const long long MOD = 1000000007;
long long H, W;
vector<string> S;
long long pos_to_id[500][500];
pair<long long, long long> id_to_pos[500];
long long Dist[500][500];
long long V;
void connect(long long i, long long j) {
  if (i > 0) {
    long long next_i = i - 1;
    long long next_j = j;
    if (S[next_i][next_j] == '.') {
      Dist[pos_to_id[i][j]][pos_to_id[next_i][next_j]] = 1;
      Dist[pos_to_id[next_i][next_j]][pos_to_id[i][j]] = 1;
    }
  }
  if (i < H - 1) {
    long long next_i = i + 1;
    long long next_j = j;
    if (S[next_i][next_j] == '.') {
      Dist[pos_to_id[i][j]][pos_to_id[next_i][next_j]] = 1;
      Dist[pos_to_id[next_i][next_j]][pos_to_id[i][j]] = 1;
    }
  }
  if (j > 0) {
    long long next_i = i;
    long long next_j = j - 1;
    if (S[next_i][next_j] == '.') {
      Dist[pos_to_id[i][j]][pos_to_id[next_i][next_j]] = 1;
      Dist[pos_to_id[next_i][next_j]][pos_to_id[i][j]] = 1;
    }
  }
  if (j < W - 1) {
    long long next_i = i;
    long long next_j = j + 1;
    if (S[next_i][next_j] == '.') {
      Dist[pos_to_id[i][j]][pos_to_id[next_i][next_j]] = 1;
      Dist[pos_to_id[next_i][next_j]][pos_to_id[i][j]] = 1;
    }
  }
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  S.resize(H);
  for (long long i = 0; i < H; ++i) {
    cin >> S[i];
  }
  memset(pos_to_id, -1, sizeof(pos_to_id));
  long long node_size = 0;
  long long root = -1;
  for (long long i = 0; i < H; ++i) {
    for (long long j = 0; j < W; ++j) {
      if (S[i][j] == '.') {
        pos_to_id[i][j] = node_size;
        id_to_pos[node_size] = make_pair(i, j);
        node_size++;
      }
    }
  }
  V = node_size;
  for (long long i = 0; i < V; ++i) {
    for (long long j = 0; j < V; ++j) {
      Dist[i][j] = (i == j) ? 0 : LLINF;
    }
  }
  for (long long i = 0; i < H; ++i) {
    for (long long j = 0; j < W; ++j) {
      connect(i, j);
    }
  }
  for (long long k = 0; k < V; ++k) {
    for (long long i = 0; i < V; ++i) {
      for (long long j = 0; j < V; ++j) {
        Dist[i][j] = min(Dist[i][j], Dist[i][k] + Dist[k][j]);
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < V; ++i) {
    for (long long j = 0; j < V; ++j) {
      ans = max(ans, Dist[i][j]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
