#include <bits/stdc++.h>
using namespace std;
int H, W;
string S[30];
int dt[30][30];
struct pos {
  int x, y;
};
queue<pos> q;
int x_mov[] = {-1, +1, 0, 0};
int y_mov[] = {0, 0, -1, +1};
int SolveMaze_bfs(int start_x, int start_y) {
  if (S[start_x][start_y] == '#') return -1;
  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      if (S[y][x] == '.')
        dt[x][y] = -1;
      else
        dt[x][y] = -23;
    }
  }
  int maxDistance = 0;
  dt[start_x][start_y] = 0;
  pos start = {start_x, start_y};
  q.push(start);
  while (!q.empty()) {
    pos current = q.front();
    q.pop();
    int cx = current.x, cy = current.y;
    int cdist = dt[cx][cy];
    for (int i = 0; i < 4; ++i) {
      int nx = cx + x_mov[i], ny = cy + y_mov[i];
      if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
      if (dt[nx][ny] != -1) continue;
      dt[nx][ny] = cdist + 1;
      if (cdist + 1 > maxDistance) maxDistance = cdist + 1;
      pos next = {nx, ny};
      q.push(next);
    }
  }
  return maxDistance;
}
void Solve() {
  int maxAns = 0;
  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      int ans = SolveMaze_bfs(x, y);
      if (ans > maxAns) maxAns = ans;
    }
  }
  cout << maxAns << endl;
}
void Init() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> S[i];
  }
}
void Clean() {}
int main() {
  Init();
  Solve();
  Clean();
  return 0;
}
