#!/usr/bin/env ruby

require 'pp'

if $0 == __FILE__
  H, W = gets.split(' ').map &:to_i
  input = []
  input = H.times.map{ gets.chomp.split('') }
#  puts "初期状態"
#  pp input

  queue = []
  (0...H).each do |i|
    (0...W).each do |j|
      if input[i][j] == '#'
        queue.push [i,j]
      end
    end
  end

  ans = 0
  loop do
    ans += 1
    tmp_queue = []

    for point in queue do
      i = point[0]
      j = point[1]

      if i-1 >= 0
        if input[i-1][j] != '#'
          input[i-1][j] = '#'
          tmp_queue.push [i-1, j]
        end
      end

      if i+1 < H
        if input[i+1][j] != '#'
          input[i+1][j] = '#'
          tmp_queue.push [i+1, j]
        end
      end

      if j-1 >= 0
        if input[i][j-1] != '#'
          input[i][j-1] = '#'
          tmp_queue.push [i, j-1]
        end
      end

      if j+1 < W
        if input[i][j+1] != '#'
          input[i][j+1] = '#'
          tmp_queue.push [i, j+1]
        end
      end
    end
#    puts "#{ans}回終了後: "
#    pp input
#    puts "Next queue"
#    pp tmp_queue

    break if input.all?{|i| i.all?{|j| j == '#' } }
    queue = tmp_queue

#    queue = []
#    tmp_map = Array.new(H) { Array.new(W, false) }
#    for point in tmp_queue do
#      i = point[0]
#      j = point[1]
#
#      if i-1 >= 0
#        if input[i-1][j] != '#' and not tmp_map[i-1][j]
#          tmp_map[i-1][j] = true
#          queue.push [i-1, j]
#        end
#      end
#
#      if i+1 < H
#        if input[i+1][j] != '#' and not tmp_map[i+1][j]
#          tmp_map[i+1][j] = true
#          queue.push [i+1, j]
#        end
#      end
#
#      if j-1 >= 0
#        if input[i][j-1] != '#' and not tmp_map[i][j-1]
#          tmp_map[i][j-1] = true
#          queue.push [i, j-1]
#        end
#      end
#
#      if j+1 < W
#        if input[i][j+1] != '#' and not tmp_map[i][j+1]
#          tmp_map[i][j+1] = true
#          queue.push [i, j+1]
#        end
#      end
#    end
#
#    puts "#{ans}回終了後: "
#    pp input
#    puts "Next queue"
#    pp queue
#
#    break if queue.empty?
  end

  puts ans
end
