#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int height, width;
  cin >> height >> width;
  vector<string> field(height);
  for (int h = 0; h < height; ++h) cin >> field[h];
  int sx, sy, gx, gy;
  int ans = 0;
  for (int h = 0; h < height; ++h) {
    for (int w = 0; w < width; ++w) {
      if (field[h][w] == '.') {
        sx = h;
        sy = w;
      }
      for (int h2 = 0; h2 < height; ++h2) {
        for (int w2 = 0; w2 < width; ++w2) {
          if (field[h2][w2] == '.' && (sx != h2 || sy != w2)) {
            gx = h2;
            gy = w2;
          }
          vector<vector<int> > dist(height, vector<int>(width, -1));
          dist[sx][sy] = 0;
          queue<pair<int, int> > que;
          que.push(make_pair(sx, sy));
          while (!que.empty()) {
            pair<int, int> current_pos = que.front();
            int x = current_pos.first;
            int y = current_pos.second;
            que.pop();
            for (int direction = 0; direction < 4; ++direction) {
              int next_x = x + dx[direction];
              int next_y = y + dy[direction];
              if (next_x < 0 || next_x >= height || next_y < 0 ||
                  next_y >= width)
                continue;
              if (field[next_x][next_y] == '#') continue;
              if (dist[next_x][next_y] == -1) {
                que.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1;
              }
            }
          }
          ans = max(ans, dist[gx][gy]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
