def count_step(blacks, i, j, max_dis)
    step = max_dis
    blacks.each{|black|
        bi = black[0]
        bj = black[1]
        step = [step,(bi-i).abs+(bj-j).abs].min
    }
    return step
end

h,w = gets.split.map &:to_i
max_dis = h+w
lines = []
blacks = []
step = 0
(0..h-1).each{|i|
    line = gets.chomp
    lines << line
    (0..w-1).each{|j|
        if(line[j] == "#")
            blacks << [i,j]
        end
    }
}
step = 0
(0..h-1).each{|i|
    (0..w-1).each{|j|
        if lines[i][j] == "."
            step = [step, count_step(blacks,i,j,max_dis)].max
        end
    }
}
puts step