#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, int end_h, int end_w) {
  std::vector<std::vector<bool>> seen(h + 2, std::vector<bool>(w + 2));
  std::queue<pairs> que;
  seen[start_h][start_w] = true;
  que.push({start_h, start_w, 0});
  while (que.size()) {
    auto cur = que.front();
    que.pop();
    seen[cur.first][cur.second] = true;
    if (cur.first == end_h && cur.second == end_w) return cur.depth;
    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});
      }
    }
  }
  return -1;
}
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++) {
      for (int t = 1; t <= h; t++) {
        for (int k = 1; k <= w; k++) {
          max = std::max(max, bfs(i, j, t, k));
        }
      }
    }
  }
  std::cout << max << std::endl;
}
