#include <bits/stdc++.h>
using namespace std;
int h, w;
int main() {
  cin >> h >> w;
  vector<string> board(h);
  for (int i = 0; i < h; i++) cin >> board.at(i);
  int rinsetu[h][w][h][w];
  std::memset(rinsetu, 1, sizeof rinsetu);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      rinsetu[i][j][i][j] = 0;
      if (i != 0) {
        if (board.at(i - 1).at(j) == '.') {
          rinsetu[i - 1][j][i][j] = 1;
          rinsetu[i][j][i - 1][j] = 1;
        }
      }
      if (j != 0) {
        if (board.at(i).at(j - 1) == '.') {
          rinsetu[i][j - 1][i][j] = 1;
          rinsetu[i][j][i][j - 1] = 1;
        }
      }
      if (i != h - 1) {
        if (board.at(i + 1).at(j) == '.') {
          rinsetu[i][j][i + 1][j] = 1;
          rinsetu[i + 1][j][i][j] = 1;
        }
      }
      if (j != w - 1) {
        if (board.at(i).at(j + 1) == '.') {
          rinsetu[i][j][i][j + 1] = 1;
          rinsetu[i][j + 1][i][j] = 1;
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; i < h; i++) {
        for (int l = 0; l < w; l++) {
          for (int m = 0; m < h; m++) {
            for (int n = 0; n < w; n++) {
              rinsetu[i][j][k][l] =
                  min(rinsetu[i][j][k][l],
                      rinsetu[i][j][m][n] + rinsetu[m][n][k][l]);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (rinsetu[i][j][k][l] > 1e7) continue;
          ans = max(ans, rinsetu[i][j][k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
