#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> C(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> C[i][j];
  }
  vector<vector<char>> d = C;
  int flag = 0;
  vector<vector<int>> dist(H, vector<int>(W)), dist2(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    if (flag == 1) break;
    for (int j = 0; j < W; j++) {
      if (flag == 1) break;
      if (C[i][j] == '.') {
        flag = 1;
        queue<pair<int, int>> q;
        q.push(pair<int, int>(i, j));
        C[i][j] = '#';
        while (!q.empty()) {
          pair<int, int> v = q.front();
          q.pop();
          int x = v.first, y = v.second;
          for (int k = 0; k < 4; k++) {
            int nx = x + dx[k], ny = y + dy[k];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && C[nx][ny] == '.') {
              dist[nx][ny] = dist[x][y] + 1;
              q.push(pair<int, int>(nx, ny));
              C[nx][ny] = '#';
            }
          }
        }
      }
    }
  }
  int ma = -1;
  int gx, gy;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (ma < dist[i][j]) {
        ma = dist[i][j];
        gx = i, gy = j;
      }
    }
  }
  queue<pair<int, int>> que;
  que.push(pair<int, int>(gx, gy));
  d[gx][gy] = '#';
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    int x = v.first, y = v.second;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && d[nx][ny] == '.') {
        dist2[nx][ny] = dist2[x][y] + 1;
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = '#';
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) ans = max(ans, dist2[i][j]);
  }
  cout << ans << endl;
}
