#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  bool g[n][m];
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) g[i][j] = s[j] == '.';
  }
  auto shortest = [&](pii start, pii end) -> int {
    set<pii> vis;
    queue<pair<pii, int>> q;
    q.push({start, 0});
    while (!q.empty()) {
      pair<pii, int> asdf = q.front();
      q.pop();
      auto p = asdf.first;
      auto d = asdf.second;
      if (vis.count(p)) continue;
      if (p == end) return d;
      vis.insert(p);
      int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
      for (int i = 0; i < 4; i++) {
        pii ne = {p.first + dir[i][0], p.second + dir[i][1]};
        if (ne.first < 0 || ne.first >= n || ne.second < 0 || ne.second >= m)
          continue;
        if (!g[ne.first][ne.second]) continue;
        q.emplace(ne, d + 1);
      }
    }
    return -1;
  };
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!g[i][j]) continue;
      for (int a = 0; a < n; a++) {
        for (int b = 0; b < m; b++) {
          if (!g[a][b]) continue;
          if (i == a && j == b) continue;
          ans = max(ans, shortest({i, j}, {a, b}));
        }
      }
    }
  }
  cout << ans << endl;
}
