attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

matrix = Array.new(attrs[0][0].to_i) { Array.new(attrs[0][1].to_i)}
blacks = []
for row in 0..matrix.size-1
    for column in 0..matrix[0].size-1
        matrix[row][column] = attrs[row+1][0][column]
        blacks << [row, column] if matrix[row][column] == '#'
    end
end

def create_blacks(matrix, blacks)
    new_blacks = []

    while !blacks.empty?
        row, col = blacks.pop
        if row > 0 && matrix[row-1][col] == '.'
            matrix[row-1][col] = '#'
            new_blacks << [row-1, col]
        end
    
        if row < matrix.size-1 && matrix[row+1][col] == '.'
            matrix[row+1][col] = '#'
            new_blacks << [row+1, col]
        end
    
        if col > 0 && matrix[row][col-1] == '.'
            matrix[row][col-1] = '#'
            new_blacks << [row, col-1]
        end
    
        if col < matrix[0].size-1 && matrix[row][col+1] == '.'
            matrix[row][col+1] = '#'
            new_blacks << [row, col+1]
        end
    end

    new_blacks
end

count = 1
while true
    count += 1
    new_blacks = create_blacks(matrix, blacks)

    break if new_blacks.empty?
end

p count