#include <bits/stdc++.h>
int h, w;
std::vector<std::vector<bool>> map;
struct pairs {
  int first;
  int second;
  int depth;
};
std::vector<std::pair<int, int>> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int bfs(int start_h, int start_w) {
  std::vector<std::vector<bool>> seen(h + 2, std::vector<bool>(w + 2));
  std::queue<pairs> que;
  std::vector<std::vector<int>> ms(h + 2, std::vector<int>(w + 2));
  seen[start_h][start_w] = true;
  que.push({start_h, start_w, 0});
  while (que.size()) {
    auto cur = que.front();
    que.pop();
    ms[cur.first][cur.second] = cur.depth;
    seen[cur.first][cur.second] = true;
    for (int i = 0; i < 4; i++) {
      if (!seen[cur.first + dir[i].first][cur.second + dir[i].second] &&
          map[cur.first + dir[i].first][cur.second + dir[i].second]) {
        que.push({cur.first + dir[i].first, cur.second + dir[i].second,
                  cur.depth + 1});
      }
    }
  }
  int aaa = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      aaa = std::max(aaa, ms[i][j]);
    }
  }
  return aaa;
}
int main() {
  std::cin >> h >> w;
  map.resize(h + 2, std::vector<bool>(w + 2));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char a;
      std::cin >> a;
      map[i][j] = a == '.';
    }
  }
  int max = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (map[i][j]) max = std::max(bfs(i, j), max);
    }
  }
  std::cout << max << std::endl;
}
