# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0156

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def bfs(field, sx, sy):
    """
    ??????????????°???????????°??????????????§??????????????????
    :param field:
    :param sx: ??????????????°????????§?¨?
    :param sy:
    :return: ????????????????????´???????????§????????¢
    """
    # ????????????????§????????????´????????§?¨?????????????
    dy = [-1, 1, 0, 0]
    dx = [0, 0, -1, 1]
    # ??°???????????????(?§????????????£????????????????????????????????§??????????????¨)
    Y = len(field)
    X = len(field[0])
    d = [[float('inf')] * X for _ in range(Y)] #  ??????????????°?????????????????¢???INF??§?????????
    moats = set()                   # ????????§???????????????????????§?¨?

    # ???????????????????????????????????°???????????´????????°????????§????????¢????±???????
    Q = deque()
    Q.append((sx, sy))
    d[sy][sx] = 0               #  ??????????????°??????????????????0
    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        for i in range(4):
            nx = cx + dx[i]
            ny = cy + dy[i]
            # ?§?????????? ??°????????????????????????????????? and ?£?????????£???????????? and ??¢?????¢?´¢?????§?????? ??´???
            if (not 0 <= nx < X) or (not 0 <= ny < Y):
                return True, moats
            elif d[ny][nx] == float('inf'):
                if field[ny][nx] == '#':
                    moats.add((nx, ny))
                else:
                    Q.append((nx, ny))
                    d[ny][nx] = d[cy][cx] + 1
    return False, moats


def fill_moat(field, moats):
    # ??¢??\???????????¨????????????????????£??????????????????'^'??§?????????
    dy = [-1, 1, 0, 0]
    dx = [0, 0, -1, 1]
    # ??°???????????????(?§????????????£????????????????????????????????§??????????????¨)
    Y = len(field)
    X = len(field[0])
    d = [[float('inf')] * X for _ in range(Y)] #  ??????????????°?????????????????¢???INF??§?????????

    while moats:
        cx, cy = moats.pop()        #  ?????¨??°?????§?¨?
        field[cy][cx] = '^'
        for i in range(4):
            nx = cx + dx[i]
            ny = cy + dy[i]
            if (0 <= nx < X) and (0 <= ny < Y) and d[ny][nx] == float('inf'):
                if field[ny][nx] == '#':
                    moats.add((nx, ny))
                    d[ny][nx] = d[cy][cx] + 1


def solve(field):
    # ??????????????°???(S)??¨??´????????°???(N)?????????
    start = (0, 0)
    for y, row in enumerate(field):
        if '&' in row:
            start = (row.index('&'), y)

    sx, sy = start
    climb = 0
    while True:
        res, moats = bfs(field, sx, sy)
        if res is False:
            climb += 1
            fill_moat(field, moats)
        else:
            break
    return climb


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

#        data = [
#         '.###.',
#         '#...#',
#         '#.&.#',
#         '#...#',
#         '.###.'
#        ]

        data = [input().strip('\n') for _ in range(m)]
        field = [list(x) for x in data] #  data????????????????????????????????????????????????
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 8928