/*
 * ninja.cpp
 *
 *  Created on: 2011/07/28
 *      Author: isa
 */

#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){
		cin >> n;
		if((m|n) == 0) break;
		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] = '.';
				}
			}
		}

		//f[^ÇÝÝ±±ÜÅ

		pair<int,int> pos;
		int num;
		q.push_back(MP(MP(x,y),0));
		//BFS
		while(1){
			if(q.empty()){
				//I¹»è
				bool ended = true;
				for(int i=0;i<n;i++){
					for(int j=0;j<m;j++){
						if(!visited[i][j]) ended = false;
						//printf("%2d", step[i][j]);
					}
					//cout << endl;
				}
				//cout << endl;
				if(ended){
					int ret = 100000;
					//I¹
					//cout << "process ended" << endl;
					for(int i=0;i<n;i++){
						ret = min(ret, step[i][0]);
						ret = min(ret, step[i][m-1]);
					}
					for(int i=0;i<m;i++){
						ret = min(ret,step[0][i]);
						ret = min(ret,step[n-1][i]);
					}
					cout << ret << endl;
					break;
				}else{
					//ÄJ
					bool find = false;
					for(int i=0;i<n && !find;i++){
						for(int j=0;j<m && !find;j++){
							//¢KâÅ
							if(!visited[i][j]){
								int tmpstep=100000;
								for(int k=0;k<4;k++){
									if(0 <= i+dx[k] && i+dx[k] <= n-1 && 0 <= j+dy[k] && j+dy[k] <= m-1){
										if(visited[i+dx[k]][j+dy[k]]){
											tmpstep = min(tmpstep, step[i+dx[k]][j+dy[k]]);
										}
									}
								}
								if(tmpstep != 100000){
									if(field[i][j] == '.'){
										q.push_back(MP(MP(i,j),tmpstep));
									}else{
										q.push_back(MP(MP(i,j),tmpstep+1));
									}
									find = true;
								}
							}
						}
					}
				}
			}

			pos = q.front().first;
			x = pos.first;
			y = pos.second;
			num = q.front().second;
			q.pop_front();
			step[x][y] = num;
			visited[x][y] = true;
			for(int i=0;i<4;i++){
				if(0 <= x+dx[i] && x+dx[i] <= n-1 && 0 <= y+dy[i] && y+dy[i] <= m-1){
					if(field[x][y] == field[x+dx[i]][y+dy[i]]){
						if(!visited[x+dx[i]][y+dy[i]] && find(q.begin(),q.end(),MP(MP(x+dx[i],y+dy[i]), num)) == q.end()){
							q.push_back(MP(MP(x+dx[i],y+dy[i]), num));
						}
					}
				}
			}
		}
	}
}