import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

enum dx = [0, 0, 1, -1];
enum dy = [1, -1, 0, 0];
enum inf = int.max;

void main() {
  auto zz = readln.split.map!(a => a.to!int).array;
  immutable h = zz[0], w = zz[1];
  auto d = new int[][h];
  foreach (i; 0 .. h) {
    d[i] = readln.take (w).map! ( (a) => (a == '#') ? 0 : inf).array;
  }
  int[] q;
  foreach (i; 0 .. h) foreach (j; 0 .. w) {
    if (d[i][j] == 0) q ~= i * w + j;
  }
  int l = 0;
  while (l < q.length) {
    int z = q[l++];
    int i = z / w, j = z % w;
    int nd = d[i][j] + 1;
    foreach (k; 0 .. 4) {
      int x = i + dx[k];
      if (x < 0 || x >= h) continue;
      int y = j + dy[k];
      if (y < 0 || y >= w) continue;
      if (d[x][y] > nd) {
        d[x][y] = nd;
        q ~= x * w + y;
      }
    }
  }
  int res = int.min;
  foreach (i; 0 .. h) {
    res = max (res, d[i].reduce!"max(a,b)");
  }
  writeln (res);
}

