def ReadMap(n, m):
  Map = [0] * m
  for i in range(m):
    a = raw_input()
    b = list(a)
    if a.count('&')>0:
      j = a.index('&')
      PosCas = [j, i]
      b[j] = '.'
    Map[i] = b
  return Map, PosCas

def fill(SP, c1, c2):
  for x, y in SP:
    try:
      if Map[y][x] != c1:continue
    except: continue
    if x in [0, n-1] or y in [0, m-1]: return 1
    Map[y][x] = c2
    SP += [[x+1, y], [x-1, y], [x, y+1], [x, y-1]]
  return 0

while 1:
  n, m = map(int, raw_input().split())
  if n == m == 0: break
  Map, PosCas = ReadMap(n, m)
  c = 0
  while 1:
    SP = [PosCas]
    if fill(SP, '.', '#'): break
    c += 1
    if fill(SP, '#', '.'): break
  print c