#include <bits/stdc++.h>
using namespace std;
static const int MAX = 10000;
static const long long INFTY = 1e12;
int dp[500][500];
void warshall_floyd(int n) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
}
int main() {
  int H, W;
  char s[30][30];
  int dp_h;
  int ans = 0;
  cin >> H >> W;
  for (int i = 0, i_len = (H); i < i_len; ++i) {
    for (int j = 0, j_len = (W); j < j_len; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0, i_len = (H * W); i < i_len; ++i) {
    for (int j = 0, j_len = (H * W); j < j_len; ++j) {
      dp[i][j] = MAX;
    }
  }
  for (int i = 0, i_len = (H); i < i_len; ++i) {
    dp_h = H * i;
    for (int j = 0, j_len = (W); j < j_len; ++j) {
      if (s[i][j + 1] == '.' && s[i][j] == '.') {
        dp[dp_h + j][dp_h + j + 1] = dp[dp_h + j + 1][dp_h + j] = 1;
      }
      if (s[i][j] == '.' && s[i + 1][j] == '.') {
        dp[dp_h + j][dp_h + j + H] = dp[dp_h + j + H][dp_h + j] = 1;
      }
    }
  }
  warshall_floyd(H * W);
  for (int i = 0; i < H * W; i++) {
    for (int j = 0; j < H * W; j++) {
      if (i != j && dp[i][j] != MAX) ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
