#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int used[25][25];
int dd[25][25];
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  char fi[h][w];
  int a, b, c, d;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> fi[i][j];
      if (fi[i][j] == '.') {
        a = i, b = j;
      }
    }
  }
  queue<pair<int, int>> q;
  q.push(make_pair(a, b));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (fi[i][j] == '.') dd[i][j] = 1e9;
    }
  }
  dd[a][b] = 0;
  c = a, d = b;
  while (q.size()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    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) {
        if (fi[nx][ny] == '#') continue;
        if (dd[nx][ny] > dd[x][y] + 1) {
          dd[nx][ny] = dd[x][y] + 1;
          q.push(make_pair(nx, ny));
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (dd[c][d] < dd[i][j]) {
        c = i, d = j;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (fi[i][j] == '.') dd[i][j] = 1e9;
    }
  }
  q.push(make_pair(c, d));
  dd[c][d] = 0;
  while (q.size()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    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) {
        if (fi[nx][ny] == '#') continue;
        if (dd[nx][ny] > dd[x][y] + 1) {
          dd[nx][ny] = dd[x][y] + 1;
          q.push(make_pair(nx, ny));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, dd[i][j]);
    }
  }
  cout << ans << endl;
}
