#include <bits/stdc++.h>
void func(std::array<std::array<int, 20>, 20>& maze, int x, int y, int step) {
  if (maze[x][y] == -100) return;
  if (maze[x][y] != -1 && maze[x][y] <= step) return;
  maze[x][y] = step;
  func(maze, x + 1, y, step + 1);
  func(maze, x - 1, y, step + 1);
  func(maze, x, y + 1, step + 1);
  func(maze, x, y - 1, step + 1);
}
int main() {
  int h{}, w{};
  std::cin >> h >> w;
  std::array<std::array<int, 20>, 20> maze{};
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 20; j++) {
      maze[i][j] = -100;
    }
  }
  char x{};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      std::cin >> x;
      if (x == '.') {
        maze[i][j] = -1;
      }
    }
  }
  int result{};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == -1) {
        auto hoge = maze;
        func(hoge, j, i, 0);
        const auto p = &(hoge[0][0]);
        const auto tmp = *(std::max_element(p, p + 400));
        result = std::max(tmp, result);
      }
    }
  }
  std::cout << result << std::endl;
  return 0;
}
