#include <bits/stdc++.h>
using i64 = long long;
int main() {
  constexpr int inf = std::numeric_limits<int>::max() / 2;
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> b(h);
  for (int i = 0; i < h; i++) {
    std::cin >> b[i];
  }
  std::vector<std::vector<int>> dist(h * w, std::vector<int>(h * w, inf));
  auto get = [w](int i, int j) { return i * w + j; };
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (b[i][j] == '#') continue;
      int k = get(i, j);
      if (i > 0 && b[i - 1][j] == '.') dist[k][get(i - 1, j)] = 1;
      if (i + 1 < h && b[i + 1][j] == '.') dist[k][get(i + 1, j)] = 1;
      if (j > 0 && b[i][j - 1] == '.') dist[k][get(i, j - 1)] = 1;
      if (j + 1 < w && b[i][j + 1] == '.') dist[k][get(i, j + 1)] = 1;
    }
  for (int k = 0; k < h * w; k++)
    for (int i = 0; i < h * w; i++)
      for (int j = 0; j < h * w; j++) {
        dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
      }
  int ret = 0;
  for (auto &v : dist)
    for (auto e : v)
      if (e < inf) ret = std::max(ret, e);
  std::cout << ret << std::endl;
  return 0;
}
