#include <bits/stdc++.h>
using namespace std;
using point = pair<int, int>;
namespace {
constexpr int kHNext[4] = {-1, 1, 0, 0};
constexpr int kWNext[4] = {0, 0, -1, 1};
}  // namespace
int64_t BFS(vector<string>& maze, int h, int w, int H, int W) {
  queue<point> q;
  q.push(make_pair(h, w));
  vector<vector<int>> dists(H, vector<int>(W, -1));
  dists[h][w] = 0;
  int max_dist = 0;
  while (!q.empty()) {
    point p = q.front();
    q.pop();
    int dist = dists[p.first][p.second];
    for (size_t i = 0; i < 4; ++i) {
      int h_next = p.first + kHNext[i];
      if (h_next < 0 || h_next == H) continue;
      int w_next = p.second + kWNext[i];
      if (w_next < 0 || w_next == W) continue;
      if (dists[h_next][w_next] != -1) continue;
      if (maze[h_next][w_next] == '#') {
        dists[h_next][w_next] = 0;
        continue;
      }
      dists[h_next][w_next] = dist + 1;
      q.push(make_pair(h_next, w_next));
      max_dist = max(max_dist, dist + 1);
    }
  }
  return max_dist;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> maze(H);
  for (size_t i = 0; i < H; ++i) {
    cin >> maze[i];
  }
  int64_t res = 0;
  for (size_t h = 0; h < H; ++h) {
    for (size_t w = 0; w < W; ++w) {
      int64_t dist = BFS(maze, h, w, H, W);
      res = max(res, dist);
    }
  }
  cout << res << endl;
  return 0;
}
