from collections import deque

dd = ((-1, 0), (0, -1), (1, 0), (0, 1))

while 1:
    N, M = map(int, input().split())
    if N == M == 0:
        break
    MP = [input() for i in range(M)]
    cost = [[-1]*N for i in range(M)]
    cur = 0
    que = deque()
    for i in range(M):
        for j in range(N):
            if MP[i][j] == '&':
                que.append((i, j))
                cost[i][j] = 0

    while que:
        r, c = que.popleft()
        s = cost[r][c]
        a = MP[r][c]
        for dr, dc in dd:
            nr = r + dr; nc = c + dc
            if not 0 <= nr < M or not 0 <= nc < N or cost[nr][nc] != -1:
                continue
            b = MP[nr][nc]
            t = s + (a != '#' and b == '#')
            cost[nr][nc] = t
            if s == t:
                que.appendleft((nr, nc))
            else:
                que.append((nr, nc))

    ans = N*M
    for i in range(M):
        ans = min(ans, cost[i][0], cost[i][-1])
    for i in range(N):
        ans = min(ans, cost[0][i], cost[-1][i])
    print(ans)
