def f(field, n, m, level=0)
  field[0][0] = "#"
  que = [[0,0]]
  until que.empty?
    y, x = que.shift
    [[-1,0],[1,0],[0,-1],[0,1]].each{|dy,dx|
      ny, nx = y+dy, x+dx
      if ny>=0 && ny<=m+1 && nx>=0 && nx<=n+1
        return level if field[ny][nx]=="&"
        if field[ny][nx]=="."
          field[ny][nx] = "#"
          que << [ny,nx]
        end
      end
    }
  end
  field[0][0] = "."
  que = [[0,0]]
  until que.empty?
    y, x = que.shift
    [[-1,0],[1,0],[0,-1],[0,1]].each{|dy,dx|
      ny, nx = y+dy, x+dx
      if ny>=0 && ny<=m+1 && nx>=0 && nx<=n+1
        if field[ny][nx]=="#"
          field[ny][nx] = "."
          que << [ny,nx]
        end
      end
    }
  end
  f(field, n, m, level+1)
end

require "pp"

loop{
  n, m = gets.split.map(&:to_i)
  break if n==0 and m==0
  field = ["."*(n+2)] + m.times.map{"." + gets.chomp + "."} + ["."*(n+2)]
  puts f(field, n, m)
}
