#include <bits/stdc++.h>
std::pair<int, int> start = std::make_pair(INT_MAX, INT_MAX);
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int H, W;
int bfs(std::vector<std::vector<int>> &world, std::pair<int, int> start) {
  std::vector<std::vector<int>> d(H, std::vector<int>(W, INT_MAX));
  std::queue<std::pair<int, int>> Q;
  Q.push(start);
  d[start.first][start.second] = 0;
  std::pair<int, int> now_coord;
  int max_d = 0;
  while (!Q.empty()) {
    now_coord = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int next_x = now_coord.first + dx[i];
      int next_y = now_coord.second + dy[i];
      if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue;
      if (world[next_x][next_y] != INT_MAX) {
        if (d[next_x][next_y] > d[now_coord.first][now_coord.second] + 1) {
          d[next_x][next_y] = d[now_coord.first][now_coord.second] + 1;
          Q.push(std::make_pair(next_x, next_y));
          if (d[next_x][next_y] > max_d) max_d = d[next_x][next_y];
        }
      }
    }
  }
  return max_d;
}
void solve(std::vector<std::vector<int>> &world) {
  int max_d = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int temp_d = bfs(world, std::make_pair(i, j));
      if (temp_d > max_d) max_d = temp_d;
    }
  }
  printf("%d\n", max_d);
}
int main() {
  scanf("%d %d%*c", &H, &W);
  std::vector<std::vector<int>> world(H, std::vector<int>(W, INT_MAX));
  for (int i = 0; i < H; i++) {
    std::string temp;
    std::cin >> temp;
    for (int j = 0; j < W; j++) {
      if (temp[j] == '.') {
        world[i][j] = 0;
        start.first = i;
        start.second = j;
      }
    }
  }
  solve(world);
  return 0;
}
