#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int fc(const vector<string> &s, int si, int sj) {
  int h = s.size(), w = s.front().size();
  vector<vector<int>> d(h, vector<int>(w, -1));
  int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1};
  queue<pair<int, int>> q;
  q.push({si, sj});
  d.at(si).at(sj) = 0;
  int res = 0;
  while (!q.empty()) {
    auto [i, j] = q.front();
    q.pop();
    for (int k = 0; k < (int)(4); k++) {
      int ni = i + di[k], nj = j + dj[k];
      if (nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
      if (s.at(ni).at(nj) == '#' || d.at(ni).at(nj) != -1) continue;
      d.at(ni).at(nj) = d.at(i).at(j) + 1;
      res = max(res, d.at(ni).at(nj));
      q.push({ni, nj});
    }
  }
  return res;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (int)(h); i++) cin >> s.at(i);
  int ans = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      ans = max(ans, fc(s, i, j));
    }
  cout << ans << endl;
  return 0;
}
