#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <string>
#include <cstring>

using namespace std;

#define MP make_pair

int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};

int main(void){
	int n,m;

	while(cin >> m && m){
		cin >> n;
		char field[n][m];
		int step[n][m];
		bool visited[n][m];
		string str;
		int x,y;
		deque<pair<pair<int,int>, int> > q;

		memset(step, -1, sizeof(step));
		memset(visited,false,sizeof(visited));
		for(int i=0;i<n;i++){
			cin >> str;
			for(int j=0;j<m;j++){
				field[i][j] = str[j];
				if(str[j] == '&'){
					x = i;
					y = j;
					field[i][j] = '.';
				}
			}
		}

		pair<int,int> pos;
		int num;
		char pos_type;
		q.push_back(MP(MP(x,y),0));
		visited[x][y] = true;
		while(1){
			if(q.empty()){
				bool find = false;
				for(int i=0;i<n && !find;i++){
					for(int j=0;j<m && !find;j++){
						if(pos_type == '.'){
							if(step[i][j] == num+1 && !visited[i][j]){
								q.push_back(MP(MP(i,j), num+1));
								find = true;
							}
						}else{
							if(step[i][j] == num && !visited[i][j]){
								q.push_back(MP(MP(i,j), num));
								find = true;
							}
						}
					}
				}
			}

			pos = q.front().first;
			x = pos.first;
			y = pos.second;
			num = q.front().second;
			q.pop_front();

			pos_type = field[x][y];

			if(x == 0 || x == n-1 || y == 0 || y == m-1){
				cout << num << endl;
				break;
			}
			step[x][y] = num;
			for(int i=0;i<4;i++){
				if(!visited[x+dx[i]][y+dy[i]]){
					if(field[x+dx[i]][y+dy[i]] == field[x][y]){
						q.push_back(MP(MP(x+dx[i], y+dy[i]), num));
						visited[x+dx[i]][y+dy[i]] = true;
					}else{
						if(pos_type == '.'){
							step[x+dx[i]][y+dy[i]] = num+1;
						}else{
							step[x+dx[i]][y+dy[i]] = num;
						}
					}
				}
			}
		}
	}
}