#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  int D = H * W;
  vector<string> S(H);
  for (int i = 0; i < (int)(H); i++) cin >> S[i];
  vector<vector<int>> d(D, vector<int>(D, 1e9));
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) {
      if (S[i][j] != '.') continue;
      for (int k = -1; k <= 1; k++)
        for (int l = -1; l <= 1; l++) {
          if (k == 0 && l == 0) {
            d[i * H + j][i * H + j] = 0;
          } else if (i + k >= 0 && i + k < H && j + l >= 0 && j + l < W &&
                     S[i + k][j + l] == '.') {
            if (k == 0 || l == 0) {
              d[i * H + j][(i + k) * H + (j + l)] = 1;
              d[(i + k) * H + j + l][i * H + j] = 1;
            }
          }
        }
    }
  for (int l = 0; l < (int)(D); l++)
    for (int i = 0; i < (int)(D); i++)
      for (int j = 0; j < (int)(D); j++)
        d[i][j] =
            ((d[i][j]) < (d[i][l] + d[l][j]) ? (d[i][j]) : (d[i][l] + d[l][j]));
  int tmp = 0;
  for (int i = 0; i < (int)(D); i++)
    for (int j = 0; j < (int)(D); j++) {
      if (d[i][j] > tmp && d[i][j] < 1e9) tmp = d[i][j];
    }
  cout << tmp << endl;
  return 0;
}
