H,W = gets.chomp.split(" ").map(&:to_i)
memoi = []
memoj = []
count = 0
A = []
flg = false
flg_count = 0
for i in 0..H-1 do
    A[i] = gets.chomp.split("").map(&:to_s)
end

while flg == false
for i in 0..H-1 do #探索
    for j in 0..W-1 do
        if A[i][j] == "#"
            memoi.push(i)
            memoj.push(j)
        else
            flg_count = flg_count + 1
        end
        if flg_count == H*W
            flg = true 
        end
    end
end

for i in 0..H-1 do #実行
    for j in 0..W-1 do
        if memoi.include?(i) && memoj.include?(j)
            if (i-1).between?(0,H-1)
                A[i-1][j] = "#"
            end  
            if (j-1).between?(0,W-1)
                A[i][j-1] = "#"
            end
            if (j+1).between?(0,W-1)
                A[i][j+1] = "#"
            end
            if (i+1).between?(0,H-1)
                A[i+1][j] = "#"
            end
        end
    end
end
count = count + 1
end

puts count