H,W=gets.split.map(&:to_i)

q = []
map = H.times.map { |y|
    s = gets.chomp
    x = 0
    while x_ = s.index('#',x)
        q << [0,x_,y]
        x = x_ + 1
    end
    s
}

# q = []
# H.times do |y|
#     W.times do |x|
#         q << [0,x,y] if map[y][x] == '#'
#     end
# end
# p q

until q.empty?
    n,x,y = q.shift
    map[y][x] = '#'
    q << [n+1,x-1,y] if 0 <= x-1 && map[y][x-1] == '.'
    q << [n+1,x+1,y] if x+1 < W  && map[y][x+1] == '.'
    q << [n+1,x,y-1] if 0 <= y-1 && map[y-1][x] == '.'
    q << [n+1,x,y+1] if y+1 < H  && map[y+1][x] == '.'
end

puts n