#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const long long MOD = 1000000007;
const long long MAX = 1000000;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a > b) {
    return b;
  }
  return a;
}
template <typename T>
void wf(T (&g)[1000][1000], T N) {
  for (int k = 1; k <= N; k++) {
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= N; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}
int main() {
  long long H, W;
  cin >> H >> W;
  char S[30][30];
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++) cin >> S[i][j];
  long long g[1000][1000];
  for (int i = 1; i <= H * W; i++)
    for (int j = 1; j <= H * W; j++) {
      g[i][j] = INF;
    }
  for (int i = 1; i <= H - 1; i++)
    for (int j = 1; j <= W; j++) {
      if (S[i][j] == '.' && S[i + 1][j] == '.') {
        g[(i - 1) * W + j][i * W + j] = 1;
        g[i * W + j][(i - 1) * W + j] = 1;
      }
    }
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W - 1; j++) {
      if (S[i][j] == '.' && S[i][j + 1] == '.') {
        g[(i - 1) * W + j][(i - 1) * W + j + 1] = 1;
        g[(i - 1) * W + j + 1][(i - 1) * W + j] = 1;
      }
    }
  wf(g, H * W);
  long long ans = 0;
  for (int i = 1; i <= H * W; i++)
    for (int j = 1; j <= H * W; j++) {
      if (g[i][j] != INF) {
        ans = max(ans, g[i][j]);
      }
    }
  cout << ans;
  system("PAUSE");
}
