h, w = gets.split.map(&:to_i)
a = []
h.times { a << gets.chomp.split('') }
ans = 0

while true
  hoge = Marshal.load(Marshal.dump(a))
  hoge.each_with_index do |e, i|
    e.each_with_index do |g, j|
      if g == '#'
        a[i-1][j] = '#' unless i == 0
        a[i][j-1] = '#' unless j == 0
        a[i][j+1] = '#' unless j == w-1
        a[i+1][j] = '#' unless i == h-1
      end
    end
  end
  ans += 1
  break unless a.flatten.include?('.')
end

puts ans