#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> map(H);
  for (auto& s : map) cin >> s;
  auto bfs = [&](int s) {
    if (map[s / W][s % W] == '#') return -1;
    vector<int> d(H * W, numeric_limits<int>::max());
    queue<pair<int, int>> qs;
    qs.emplace(s, 0);
    while (not qs.empty()) {
      auto q = qs.front();
      qs.pop();
      auto s = get<0>(q);
      auto dis = get<1>(q);
      d[s] = dis;
      if (s % W > 0) {
        auto t = s - 1;
        if (map[t / W][t % W] == '.' and d[t] > dis + 1) {
          qs.emplace(t, dis + 1);
        }
      }
      if (s % W != W - 1) {
        auto t = s + 1;
        if (map[t / W][t % W] == '.' and d[t] > dis + 1) {
          qs.emplace(t, dis + 1);
        }
      }
      if (s / W > 0) {
        auto t = s - W;
        if (map[t / W][t % W] == '.' and d[t] > dis + 1) {
          qs.emplace(t, dis + 1);
        }
      }
      if (s / W != H - 1) {
        auto t = s + W;
        if (map[t / W][t % W] == '.' and d[t] > dis + 1) {
          qs.emplace(t, dis + 1);
        }
      }
    }
    auto res = 0;
    for (auto v : d) {
      if (v == numeric_limits<int>::max()) continue;
      res = max(res, v);
    }
    return res;
  };
  auto ans = 0;
  for (int i = 0; i < H * W; i++) {
    ans = max(ans, bfs(i));
  }
  cout << ans << endl;
  return 0;
}
