#include <bits/stdc++.h>
using namespace std;
int h, w;
bool is_valid_move(vector<string> &board, vector<vector<bool>> &checked, int y,
                   int x, int c, vector<vector<int>> &count_step) {
  if (x <= -1 || x >= w || y <= -1 || y >= h) {
    return false;
  }
  if (board.at(y).at(x) == '#') {
    return false;
  }
  if (count_step.at(y).at(x) < c + 1) {
    return false;
  }
  return true;
}
void fill_island(vector<string> &board, vector<vector<bool>> &checked, int y,
                 int x, int c, vector<vector<int>> &count_step) {
  checked.at(y).at(x) = true;
  if (count_step.at(y).at(x) == 1000) count_step.at(y).at(x) = c;
  if (count_step.at(y).at(x) > c) count_step.at(y).at(x) = c;
  if (is_valid_move(board, checked, y - 1, x, c, count_step)) {
    fill_island(board, checked, y - 1, x, c + 1, count_step);
  }
  if (is_valid_move(board, checked, y, x + 1, c, count_step)) {
    fill_island(board, checked, y, x + 1, c + 1, count_step);
  }
  if (is_valid_move(board, checked, y + 1, x, c, count_step)) {
    fill_island(board, checked, y + 1, x, c + 1, count_step);
  }
  if (is_valid_move(board, checked, y, x - 1, c, count_step)) {
    fill_island(board, checked, y, x - 1, c + 1, count_step);
  }
}
int main() {
  cin >> h >> w;
  vector<string> board(w);
  for (int i = 0; i < h; i++) {
    cin >> board.at(i);
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (board.at(i).at(j) == '#') continue;
      vector<vector<bool>> checked(h, vector<bool>(w, false));
      vector<vector<int>> count_step(h, vector<int>(w, 1000));
      fill_island(board, checked, i, j, 0, count_step);
      int ijmax = 0;
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (board.at(k).at(l) == '#') continue;
          ijmax = max(ijmax, count_step.at(k).at(l));
        }
      }
      ans = max(ans, ijmax);
    }
  }
  cout << ans << endl;
}
