#include <bits/stdc++.h>
using namespace std;
long long dis[40][40];
char l[40][40];
queue<pair<int, int> > q;
long long ma;
pair<int, int> maj;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 30; j++) dis[i][j] = -1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> l[i][j];
  }
  bool t = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (l[i][j] == '.') {
        q.push({i, j});
        dis[i][j] = 0;
        t = 0;
        break;
      }
    }
    if (t == 0) break;
  }
  while (q.size()) {
    int i = q.front().first, j = q.front().second;
    q.pop();
    if (dis[i][j] > ma) {
      ma = dis[i][j];
      maj = {i, j};
    }
    if (i + 1 < n and l[i + 1][j] == '.' and dis[i + 1][j] == -1) {
      dis[i + 1][j] = dis[i][j] + 1;
      q.push({i + 1, j});
    }
    if (j + 1 < m and l[i][j + 1] == '.' and dis[i][j + 1] == -1) {
      dis[i][j + 1] = dis[i][j] + 1;
      q.push({i, j + 1});
    }
    if (i - 1 > -1 and l[i - 1][j] == '.' and dis[i - 1][j] == -1) {
      dis[i - 1][j] = dis[i][j] + 1;
      q.push({i - 1, j});
    }
    if (j - 1 > -1 and l[i][j - 1] == '.' and dis[i][j - 1] == -1) {
      dis[i][j - 1] = dis[i][j] + 1;
      q.push({i, j - 1});
    }
  }
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 30; j++) dis[i][j] = -1;
  }
  q.push(maj);
  dis[maj.first][maj.second] = 0;
  while (q.size()) {
    int i = q.front().first, j = q.front().second;
    q.pop();
    if (dis[i][j] > ma) ma = dis[i][j];
    if (i + 1 < n and l[i + 1][j] == '.' and dis[i + 1][j] == -1) {
      dis[i + 1][j] = dis[i][j] + 1;
      q.push({i + 1, j});
    }
    if (j + 1 < m and l[i][j + 1] == '.' and dis[i][j + 1] == -1) {
      dis[i][j + 1] = dis[i][j] + 1;
      q.push({i, j + 1});
    }
    if (i - 1 > -1 and l[i - 1][j] == '.' and dis[i - 1][j] == -1) {
      dis[i - 1][j] = dis[i][j] + 1;
      q.push({i - 1, j});
    }
    if (j - 1 > -1 and l[i][j - 1] == '.' and dis[i][j - 1] == -1) {
      dis[i][j - 1] = dis[i][j] + 1;
      q.push({i, j - 1});
    }
  }
  cout << ma;
}
