#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const int INF = 1 << 30;
using cost_type = int;
using edge = std::pair<int, cost_type>;
template <typename T>
using Matrix = std::vector<std::vector<T>>;
Matrix<cost_type> Warshall_Floyd(const std::vector<std::vector<edge>> &from) {
  const int N = from.size();
  Matrix<cost_type> d(N, std::vector<cost_type>(N, INF));
  for (int i = 0; i < N; ++i) {
    d[i][i] = 0;
    for (auto &e : from[i]) {
      d[i][e.first] = std::min(d[i][e.first], e.second);
    }
  }
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (d[i][k] < INF && d[k][j] < INF) {
          d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
  }
  return d;
}
int main() {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::vector<char>> S(H, std::vector<char>(W));
  Matrix<int> id(H, std::vector<int>(W));
  int cnt = 0;
  for (int(i) = 0; i < (H); ++(i)) {
    for (int(j) = 0; j < (W); ++(j)) {
      std::cin >> S[i][j];
      id[i][j] = cnt;
      ++cnt;
    }
  }
  std::vector<std::vector<edge>> from(cnt);
  const std::vector<std::pair<int, int>> diff = {
      std::make_pair(-1, 0), std::make_pair(1, 0), std::make_pair(0, -1),
      std::make_pair(0, 1)};
  for (int(i) = 0; i < (H); ++(i)) {
    for (int(j) = 0; j < (W); ++(j)) {
      std::cout << i << " " << j << '\n';
      if (S[i][j] == '#') {
        continue;
      }
      for (auto d : diff) {
        int x = i + d.first;
        int y = j + d.second;
        if (0 <= x && x < H && 0 <= y && y < W && S[x][y] == '.') {
          from[id[i][j]].push_back(std::make_pair(id[x][y], 1));
        }
      }
    }
  }
  Matrix<int> d = Warshall_Floyd(from);
  int ans = 0;
  for (int(i) = 0; i < (cnt); ++(i)) {
    for (int(j) = 0; j < (cnt); ++(j)) {
      if (d[i][j] == INF) continue;
      ans = std::max(ans, d[i][j]);
    }
  }
  std::cout << ans << '\n';
}
