h, w = gets.split.map(&:to_i)

$visit = Array.new(h) {Array.new(w, false)}
$que = []
h.times do |i|
    gets.each_char.with_index do |c, j|
        if c == "#"
            $que << [i, j] 
            $visit[i][j] = 0
        end
    end
end

def calc(bool, i, j, ni, nj)
    if bool && !$visit[i + ni][j + nj]
        $que << [i + ni, j + nj]
        $ans = $visit[i + ni][j + nj] = $visit[i][j] + 1
    end
end

$ans = 0
while ij = $que.shift
    i, j = ij

    calc(i > 0, i, j, -1, 0)
    calc(i < h - 1, i, j, 1, 0)
    calc(j > 0, i, j, 0, -1)
    calc(j < w - 1, i, j, 0, 1)
end

puts $ans