from heapq import heappush, heappop

while True:
  n, m = map(int, input().split())
  if n == 0: break

  mp = ["X" + input() + "X" for _ in range(m)]
  mp.insert(0, "X" * (n + 2))
  mp.append("X" * (n + 2))
  
  que = []
  visited = [[False] * (n + 2) for _ in range(m + 2)]
  for i in range(1, n + 1):
    c1 = 1 if mp[1][i] == "#" else 0
    c2 = 1 if mp[m][i] == "#" else 0
    heappush(que, (c1, (i, 1)))
    heappush(que, (c2, (i, m)))
    visited[1][i] = True
    visited[m][i] = True
  for i in range(1, m + 1):
    c1 = 1 if mp[i][1] == "#" else 0
    c2 = 1 if mp[i][n] == "#" else 0
    heappush(que, (c1, (1, i)))
    heappush(que, (c2, (n, i)))
    visited[i][1] = True
    visited[i][n] = True
  
  direct = ((0, 1), (0, -1), (1, 0), (-1, 0))
  reached = False
  
  while que and not reached:
    cost, point = heappop(que)
    x, y = point
    for dx, dy in direct:
      newx, newy = x + dx, y + dy
      if not visited[newy][newx]:
        visited[newy][newx] = True
        if mp[newy][newx] == "&":
          print(cost)
          reached = True
          break
        if mp[newy][newx] == "#":
          heappush(que, (cost + 1, (newx, newy)))
        elif mp[newy][newx] == ".":
          heappush(que, (cost, (newx, newy)))
