#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  std::vector<std::string> table(h);
  for (auto& row : table) {
    cin >> row;
  }
  const auto size = h * w;
  std::vector<std::vector<std::size_t>> dist_table(
      size, std::vector<std::size_t>(
                size, std::numeric_limits<std::uint32_t>::max()));
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (y > 0 && table[y][x] == '.' && table[y - 1][x] == '.') {
        const auto idx1 = y * w + x;
        const auto idx2 = (y - 1) * w + x;
        dist_table[idx1][idx2] = dist_table[idx2][idx1] = 1;
      }
      if (x > 0 && table[y][x] == '.' && table[y][x - 1] == '.') {
        const auto idx1 = y * w + x;
        const auto idx2 = y * w + x - 1;
        dist_table[idx1][idx2] = dist_table[idx2][idx1] = 1;
      }
    }
  }
  for (int k = 0; k < size; k++) {
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < size; j++) {
        dist_table[i][j] =
            min(dist_table[i][j], dist_table[i][k] + dist_table[k][j]);
      }
    }
  }
  int ans = 0;
  for (auto& row : dist_table) {
    for (auto dist : row) {
      if (dist < std::numeric_limits<std::uint32_t>::max()) {
        ans = std::max<int>(ans, dist);
      }
    }
  }
  cout << ans << endl;
}
