#include <bits/stdc++.h>
int H, W;
bool S[20][20];
int dist[20][20];
void reset() {
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 20; ++j) {
      dist[i][j] = -1;
    }
  }
}
int calc_max_path(int i, int j) {
  std::vector<std::pair<int, int>> direction = {
      {1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  dist[i][j] = 0;
  std::queue<std::pair<int, int>> queue;
  queue.push({i, j});
  int max = 0;
  while (queue.empty() == false) {
    const auto& p = queue.front();
    queue.pop();
    int cur_x = p.first, cur_y = p.second;
    for (const auto& d : direction) {
      int dx = cur_x + d.first, dy = cur_y + d.second;
      if (dx < 0 || dx > H || dy < 0 || dy > W) {
        continue;
      }
      if (S[dx][dy] == false) {
        continue;
      }
      if (dist[dx][dy] != -1) {
        continue;
      }
      dist[dx][dy] = dist[cur_x][cur_y] + 1;
      max = std::max(max, dist[dx][dy]);
      queue.push({dx, dy});
    }
  }
  return max;
}
int main() {
  std::cin >> H >> W;
  char c;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      std::cin >> c;
      if (c == '.') {
        S[i][j] = true;
      } else {
        S[i][j] = false;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j] == false) {
        continue;
      }
      reset();
      const int r = calc_max_path(i, j);
      max = std::max(max, r);
    }
  }
  std::cout << max << std::endl;
  return 0;
}
