#include <iostream>
#include <cstring>
#include <set>
using namespace std;

const int SIZE = 102;
const int OFFSET = 50;
const int dir[ 4 ][ 2 ] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };

int main()
{
	int n, m;

	while( cin >> n >> m && ( n || m ) ){
		int map[ SIZE ][ SIZE ];
		memset( map, 0, sizeof(map) );
		int sx, sy;
		for( int i = 1; i < m + 1; ++i ){
			for( int j = 1; j < n + 1; ++j ){
				char c;
				cin >> c;
				if( c == '&' ){
					sx = j;
					sy = i;
					c = OFFSET + 1;
				}
				map[ i ][ j ] = c;
			}
		}
		set< pair< int, int > > q;
		q.insert( make_pair( sx, sy ) );

		int count = OFFSET;
		bool end = false;
		while( !end ){
			set< pair< int, int > > nextq;
			++count;
			while( !q.empty() ){
				pair< int, int > p = *(q.begin());
				q.erase( q.begin() );
				char a = count % 2 ? '.' : '#';
				char b = count % 2 ? '#' : '.';

				for( int i = 0; i < 4; ++i ){
					int x = p.first + dir[ i ][ 0 ];
					int y = p.second + dir[ i ][ 1 ];
					char c = map[ y ][ x ];
					if( c == 0 ){
						end = true;
						break;
					}
					if( c == a ){
						map[ y ][ x ] = count;
						q.insert( make_pair( x, y ) );
					}
					if( c == b ){
						map[ y ][ x ] = count + 1;
						nextq.insert( make_pair( x, y ) );
					}
				}
				if( end ) break;
			}
			if( end ) break;
			q = nextq;
		}
		cout << ( count - OFFSET ) / 2 << endl;
	}

	return 0;
}