#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
int h, w, dis[MAXN][MAXN], ans, farX, farY;
char maze[MAXN][MAXN];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void bfs(int x, int y) {
  memset(dis, -1, sizeof(dis));
  queue<int> q;
  q.push(x);
  q.push(y);
  dis[x][y] = 0;
  ans = 0;
  farX = x;
  farY = y;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    y = q.front();
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int xx = x + dx[i];
      int yy = y + dy[i];
      if (xx > 0 && xx <= h && yy > 0 && yy <= w && maze[xx][yy] == '.' &&
          dis[xx][yy] == -1) {
        dis[xx][yy] = dis[x][y] + 1;
        q.push(xx);
        q.push(yy);
        if (dis[xx][yy] > ans) {
          ans = dis[xx][yy];
          farX = xx;
          farY = yy;
        }
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      cin >> maze[i][j];
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (maze[i][j] == '.') {
        bfs(i, j);
        break;
      }
    }
  }
  bfs(farX, farY);
  cout << ans << endl;
  return 0;
}
