#include <bits/stdc++.h>
using namespace std;
const int V_MAX = 400;
const int INF = 1e6;
int V;
int d[V_MAX][V_MAX];
void warshall_floyd() {
  for (int k = 0; k < (int)(V); k++)
    for (int i = 0; i < (int)(V); i++)
      for (int j = 0; j < (int)(V); j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
const int H_MAX = 20;
const int W_MAX = 20;
int H, W;
char S[H_MAX][W_MAX + 1];
int v(int i, int j) { return i * W + j; }
void solve() {
  V = H * W;
  fill(d[0], d[V], INF);
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) {
      if (S[i][j] == '#') continue;
      if (i > 0 && S[i - 1][j] == '.') d[v(i, j)][v(i - 1, j)] = 1;
      if (i + 1 < H && S[i + 1][j] == '.') d[v(i, j)][v(i + 1, j)] = 1;
      if (j > 0 && S[i][j - 1] == '.') d[v(i, j)][v(i, j - 1)] = 1;
      if (j + 1 < W && S[i][j + 1] == '.') d[v(i, j)][v(i, j + 1)] = 1;
    }
  warshall_floyd();
  int ans = 0;
  for (int i = 0; i < (int)(V); i++)
    for (int j = 0; j < (int)(V); j++) {
      if (d[i][j] < INF) ans = max(ans, d[i][j]);
    }
  printf("%d\n", ans);
}
void input() {
  scanf("%d%d", &H, &W);
  for (int i = 0; i < (int)(H); i++) scanf("%s", S[i]);
}
int main() {
  input();
  solve();
  return 0;
}
