#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  for (int i = 0; (i64)(i) < (i64)(H); ++i) {
    cin >> grid[i];
  }
  auto bfs = [&](int r, int c) -> tuple<int, int, int> {
    vector<int> dx = {0, 0, 1, -1};
    vector<int> dy = {1, -1, 0, 0};
    vector<string> g = grid;
    deque<tuple<int, int, int>> q;
    int maxd = -1;
    int mr = -1, mc = -1;
    q.emplace_back(r, c, 0);
    g[r][c] = 'x';
    while (q.size()) {
      auto [r1, c1, d1] = q.front();
      q.pop_front();
      if (maxd < d1) {
        maxd = d1;
        mr = r1;
        mc = c1;
      }
      for (int i = 0; (i64)(i) < (i64)(4); ++i) {
        int r2 = r1 + dx[i];
        int c2 = c1 + dy[i];
        if (r2 < 0 || r2 >= H || c2 < 0 || c2 >= W) continue;
        if (g[r2][c2] != '.') continue;
        g[r2][c2] = 'x';
        q.emplace_back(r2, c2, d1 + 1);
      }
    }
    return {mr, mc, maxd};
  };
  for (int r = 0; (i64)(r) < (i64)(H); ++r)
    for (int c = 0; (i64)(c) < (i64)(W); ++c) {
      if (grid[r][c] == '.') {
        auto [r1, c1, _] = bfs(r, c);
        auto [r2, c2, d2] = bfs(r1, c1);
        cout << d2 << endl;
        return 0;
      }
    }
}
