io = STDIN
h,w=io.gets.split.map(&:to_i)
$board=[]
$board << [" "]*(w+2)
h.times do
  $board << ([" "]+io.gets.chomp.split(//)+[" "])
end
$board << [" "]*(w+2)
require 'pp'
queue=[]
cur=0
(1..h).each do |i|
  (1..w).each do |j|
    if $board[i][j]=="#"
      queue << [i,j]
      $board[i][j]=cur
    end
  end
end
while (a=queue.shift)
  i,j=a
  cur=$board[i][j]
  [[1,0],[0,-1],[-1,0],[0,1]].each do |x,y|
    ki,kj=x+i,y+j
    if $board[ki][kj]=="."
      $board[ki][kj]=cur+1
      queue << [ki,kj]
    end
  end
end
p cur
