#include <bits/stdc++.h>
using namespace std;
char s[30][30];
int num[30][30];
queue<pair<int, int> > q;
int main() {
  int h, w, state = 0;
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
      if (state == 0 && s[i][j] == '.') {
        num[i][j] == 1;
        q.push({i, j});
        state = 1;
      }
    }
  }
  int i, j;
  while (!q.empty()) {
    i = q.front().first, j = q.front().second;
    if (i - 1 != 0 && s[i - 1][j] == '.' && num[i - 1][j] == 0) {
      q.push({i - 1, j});
      num[i - 1][j] = num[i][j] + 1;
    }
    if (i != h && s[i + 1][j] == '.' && num[i + 1][j] == 0) {
      q.push({i + 1, j});
      num[i + 1][j] = num[i][j] + 1;
    }
    if (j - 1 != 0 && s[i][j - 1] == '.' && num[i][j - 1] == 0) {
      q.push({i, j - 1});
      num[i][j - 1] = num[i][j] + 1;
    }
    if (j != w && s[i][j + 1] == '.' && num[i][j + 1] == 0) {
      q.push({i, j + 1});
      num[i][j + 1] = num[i][j] + 1;
    }
    q.pop();
  }
  memset(num, 0, sizeof(num));
  num[i][j] = 1;
  q.push({i, j});
  while (!q.empty()) {
    i = q.front().first, j = q.front().second;
    if (i - 1 != 0 && s[i - 1][j] == '.' && num[i - 1][j] == 0) {
      q.push({i - 1, j});
      num[i - 1][j] = num[i][j] + 1;
    }
    if (i != h && s[i + 1][j] == '.' && num[i + 1][j] == 0) {
      q.push({i + 1, j});
      num[i + 1][j] = num[i][j] + 1;
    }
    if (j - 1 != 0 && s[i][j - 1] == '.' && num[i][j - 1] == 0) {
      q.push({i, j - 1});
      num[i][j - 1] = num[i][j] + 1;
    }
    if (j != w && s[i][j + 1] == '.' && num[i][j + 1] == 0) {
      q.push({i, j + 1});
      num[i][j + 1] = num[i][j] + 1;
    }
    q.pop();
  }
  cout << num[i][j] - 1 << endl;
  return 0;
}
