tdio.h>          // printf(), fprintf(), scanf()
#include <stdlib.h>         // exit()
#include <stdbool.h>

#define SZ_FIELD 100
#define QUE_SIZE 10000

typedef struct que_tbl
{
	int x;
	int y;
} que_t;

int N, M;
char field[SZ_FIELD][SZ_FIELD + 1];
que_t queue[QUE_SIZE];
int que_in;
int que_out;

void
cleanup(int ecode)
{
	exit(ecode);
}

int
que_empty()
{
	return que_in == que_out;
}

void
que_push(que_t *que)
{
	queue[que_in].x = que->x;
	queue[que_in].y = que->y;
	que_in = (que_in + 1) % QUE_SIZE;

	if (que_in == que_out)
	{
		fprintf(stderr, "Queue overflow. size:%d\n", QUE_SIZE);
		cleanup(1);
	}
}

void
que_pop()
{
	if (que_out == que_in)
	{
		fprintf(stderr, "Queue underflow\n");
		cleanup(1);
	}

	que_out = (que_out + 1) % QUE_SIZE;
}

void
que_front(que_t *que)
{
	que->x = queue[que_out].x;
	que->y = queue[que_out].y;
}

void
dfs(int x, int y)
{
	field[y][x] = '.';
	for (int dy = -1; dy <= 1; ++dy)
	{
		for (int dx = -1; dx <= 1; ++dx)
		{
			int nx = x + dx, ny = y + dy;
			if (0 <= nx && nx < N && 0 <= ny && ny < M && field[ny][nx] == '#')
				dfs(nx, ny);
		}
	}
}

bool
bfs(int *cx, int *cy)
{
	const int dx[4] = {-1, 0, 1, 0};
	const int dy[4] = { 0,-1, 0, 1};
	int mx = 0, my = 0;
	que_t que;

	que_in = 0;
	que_out = 0;

	que.x = *cx, que.y = *cy;
	que_push(&que);

	while (!que_empty())
	{
		que_front(&que); que_pop();
		int x = que.x, y = que.y;
		if (x == 0 || x == N - 1 || y == 0 || y == M - 1)
			return true;

		for (int i = 0; i < 4; ++i)
		{
			int nx = x + dx[i], ny = y + dy[i];
			if (0 <= nx && nx < N && 0 <= ny && ny < M)
			{
				if (field[ny][nx] == '.')
				{
					field[ny][nx] = ' ';
					que.x = nx, que.y = ny;
					que_push(&que);
				}
				else if (field[ny][nx] == '#')
				{
					if (nx > mx || ny > my)
						mx = nx, my = ny;
				}
			}
		}
	}

	*cx = mx, *cy = my;
	return false;
}

int
solve()
{
	int cx, cy;

	for (cy = 0; cy < M; ++cy)
	{
		for (cx = 0; cx < N; ++cx)
		{
			if (field[cy][cx] == '&')
				break;
		}

		if (cx < N)
			break;
	}

	field[cy][cx] = ' ';
	int count = 0;
	while (!bfs(&cx, &cy))
	{
		dfs(cx, cy);
		count++;
	}

	return count;
}

int
main(int argc, char **argv)
{
	while (true)
	{
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0)
			break;

		for (int i = 0; i < M; ++i)
			scanf("%s", &field[i][0]);

		printf("%d\n", solve());
	}

	return 0;
}
