#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int y = 0; y < H; y++) cin >> S[y];
  struct Point {
    int x;
    int y;
    int t;
  };
  const int dx[] = {-1, 0, +1, 0};
  const int dy[] = {0, -1, 0, +1};
  int answer = 0;
  for (int sy = 0; sy < H; sy++) {
    for (int sx = 0; sx < W; sx++) {
      if (S[sy][sx] == '#') continue;
      queue<Point> q;
      q.push({sx, sy, 0});
      vector<vector<bool>> visit(H, vector<bool>(W, false));
      int max_dist = 0;
      while (!q.empty()) {
        Point p = q.front();
        q.pop();
        max_dist = max(max_dist, p.t);
        visit[p.y][p.x] = true;
        for (int d = 0; d < 4; d++) {
          int nx = p.x + dx[d];
          int ny = p.y + dy[d];
          if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
          if (visit[ny][nx]) continue;
          if (S[ny][nx] == '#') continue;
          q.push({nx, ny, p.t + 1});
        }
      }
      answer = max(answer, max_dist);
    }
  }
  cout << answer << endl;
  return 0;
}
