class Queue
  include Enumerable

  def initialize(size = 0)
    @ary = Array.new(size)
    @first = 0
    @last = 0
  end

  def dequeue
    return nil if @first >= @last

    v = @ary[@first]
    @ary[@first] = nil
    @first += 1
    v
  end

  def each
    (@first..@last).each do |i|
      yield @ary[i]
    end
  end

  def empty?
    @first >= @last
  end

  def enqueue(v)
    @last += 1
    @ary.push(v)
    nil
  end

  def size
    @last - @first
  end
end

H, W = gets.split.map(&:to_i)
board = H.times.map { gets.chomp.chars }

queue = Queue.new
(0...H).each do |i|
  (0...W).each do |j|
    col = board[i][j]
    if col == '#'
      queue.enqueue([i, j])
    end
  end
end

current_size = queue.size
next_size = 0
t_count = 0
turned = false
count = 0
while !queue.empty?
  i, j = queue.dequeue
  t_count += 1
  if i > 0 && board[i - 1][j] == '.'
    board[i - 1][j] = '#'
    queue.enqueue([i - 1, j])
    next_size += 1
    turned = true
  end
  if i < H - 1 && board[i + 1][j] == '.'
    board[i + 1][j] = '#'
    queue.enqueue([i + 1, j])
    next_size += 1
    turned = true
  end
  if j > 0 && board[i][j - 1] == '.'
    board[i][j - 1] = '#'
    queue.enqueue([i, j - 1])
    next_size += 1
    turned = true
  end
  if j < W - 1 && board[i][j + 1] == '.'
    board[i][j + 1] = '#'
    queue.enqueue([i, j + 1])
    next_size += 1
    turned = true
  end
  if t_count == current_size
    current_size = next_size
    if turned
      count += 1
    end
    next_size = 0
    turned = false
    t_count = 0
  end
end
puts count
