#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};
bool in_road(int hh, int ww, vector<string> &tbl) {
  const int h = tbl.size();
  const int w = tbl[0].length();
  return 0 <= hh && hh < h && 0 <= ww && ww < w && tbl[hh][ww] == '.';
}
int bfs(int start_h, int start_w, vector<string> &tbl) {
  const int h = tbl.size();
  const int w = tbl[0].length();
  queue<pair<int, pii>> q;
  int ret = -1;
  vector<vector<bool>> done(h, vector<bool>(w, false));
  if (in_road(start_h, start_w, tbl))
    q.push(make_pair(0, make_pair(start_h, start_w)));
  while (!q.empty()) {
    auto tmp = q.front();
    auto tmp_len = tmp.first;
    ret = max(ret, tmp_len);
    auto tmp_pos = tmp.second;
    auto tmp_h = tmp_pos.first;
    auto tmp_w = tmp_pos.second;
    for (int i = 0; i < 4; i++) {
      const int tmp_hh = tmp_h + dh[i];
      const int tmp_ww = tmp_w + dw[i];
      if (in_road(tmp_hh, tmp_ww, tbl) && !done[tmp_hh][tmp_ww]) {
        q.push(make_pair(tmp_len + 1, make_pair(tmp_hh, tmp_ww)));
      }
    }
    q.pop();
    done[tmp_h][tmp_w] = true;
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  int h, w;
  cin >> h >> w;
  vector<string> tbl(h);
  for (int i = 0; i < h; i++) {
    cin >> tbl[i];
  }
  int ret = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ret = max(ret, bfs(i, j, tbl));
    }
  }
  cout << ret << endl;
  return 0;
}
