#include <bits/stdc++.h>
using lli = long long int;
void warshall_floyd(std::vector<std::vector<lli>>& dist) {
  int N = dist.size();
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
        dist[j][i] = dist[i][j];
      }
    }
  }
}
int main() {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::vector<lli>> dist(H * W,
                                     std::vector<lli>(H * W, 1000000000000));
  std::vector<std::vector<char>> map(H, std::vector<char>(W));
  for (int i = 0; i < H * W; i++) dist[i][i] = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      std::cin >> map[i][j];
      if (j > 0) {
        if (map[i][j] == '.' && map[i][j - 1] == '.') {
          dist[i * H + j][i * H + j - 1] = 1;
          dist[i * H + j - 1][i * H + j] = 1;
        }
      }
      if (i > 0) {
        if (map[i][j] == '.' && map[i - 1][j] == '.') {
          dist[i * H + j][(i - 1) * H + j] = 1;
          dist[(i - 1) * H + j][i * H + j] = 1;
        }
      }
    }
  }
  warshall_floyd(dist);
  lli max_dist = 0;
  for (int i = 0; i < H * W; i++) {
    for (int j = 0; j < H * W; j++) {
      if (dist[i][j] != 1000000000000) {
        max_dist = std::max(max_dist, dist[i][j]);
      }
    }
  }
  std::cout << max_dist << std::endl;
  return 0;
}
