#include <bits/stdc++.h>
int H, W;
int df(int x, int y, int xg, int yg, int n, std::vector<std::string> map) {
  if (x == xg && y == yg) return n;
  map[x][y] = '#';
  int ret = 1000;
  if (0 < x && map[x - 1][y] == '.')
    ret = std::min(ret, df(x - 1, y, xg, yg, n + 1, map));
  if (x + 1 < H && map[x + 1][y] == '.')
    ret = std::min(ret, df(x + 1, y, xg, yg, n + 1, map));
  if (0 < y && map[x][y - 1] == '.')
    ret = std::min(ret, df(x, y - 1, xg, yg, n + 1, map));
  if (y + 1 < W && map[x][y + 1] == '.')
    ret = std::min(ret, df(x, y + 1, xg, yg, n + 1, map));
  return ret;
}
int main() {
  std::cin >> H >> W;
  std::vector<std::string> S(H);
  for (int i = 0; i < H; ++i) std::cin >> S[i];
  int ans;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j] == '#') continue;
      for (int k = 0; k < H; ++k) {
        for (int l = 0; l < W; ++l) {
          if (S[k][l] == '#') continue;
          ans = std::max(ans, df(i, j, k, l, 0, S));
        }
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
