h,w = gets.split.map(&:to_i)
a = h.times.map{gets.chomp}
dist = Array.new(h).map{Array.new(w,10000)}
d = [0,1,0,-1]
que = []
h.times do |i|
    w.times do |j|
        if a[i][j] == "#"
            dist[i][j] = 0
            que.push([i,j])
        end
    end
end
while que.any?
    f = que.shift
    4.times do |i|
        x = f[0]+d[i]
        y = f[1]+d[i^1]
        next if x < 0 || x >= h || y < 0 || y >= w
        if dist[x][y] > 9999
            dist[x][y] = dist[f[0]][f[1]]+1
            que.push([x,y])
        end
    end
end
ans = 0
dist.each do |arr|
    ans = arr.max if ans < arr.max
end
puts ans
