#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

void label(vector<vector<char> >& dt, char sdt, vector<vector<int> >& lb, int slb)
{
	int h = dt.size();
	int w = dt[0].size();

	bool flag; // YÓª êÎ[v·é
	do
	{
		flag=false;
		
		// O¤ÈOÌSZÉÎµ
		for(int i=1; i<h-1; i++)
		{
			for(int j=1; j<w-1; j++)
			{
				// õ¶ñÅxª¢Ýè
				if(dt[i][j]==sdt && lb[i][j]==-1)
				{
					// ×ÚZÉõxª êÎ
					if(lb[i][j+1]==slb || lb[i+1][j]==slb
					|| lb[i][j-1]==slb || lb[i-1][j]==slb)
					{
						// xðÝèµA½tOð§Äé
						lb[i][j] = slb;
						flag = true;
					}
				}
			}
		}
	}
	while(flag);
	
	return;
}

int main()
{
	stringstream ss;
	
	// üÍ
	int wid,hei,tmp,targetX,targetY;
	while(1)
	{
		cin >> wid >> hei;
		if(wid==0 && hei==0) { break; } // 0 0 ÅI¹
		
		// lûðêZ¸ÂgåµÄÌæðmÛ
		wid+=2; hei+=2;
		vector<vector<char> > map_data(hei,vector<char>(wid));
		vector<vector<int> > lab_data(hei,vector<int>(wid));
		
		// MAPð'.'ÅALabelð0Åú»
		for(int i=0; i<hei; i++)
		for(int j=0; j<wid; j++)
		{
			map_data[i][j] = '.';
			lab_data[i][j] = 0;
		}

		// f[^ðüÍAxÉ-1ðÝè
		for(int i=1; i<hei-1; i++)
		{
			for(int j=1; j<wid-1; j++)
			{
				while(1)
				{
					char pk=cin.peek();
					if(pk=='.' || pk=='#')
					{
						map_data[i][j] = cin.get();
						lab_data[i][j] = -1;
						break;
					}
					else if(pk=='&')
					{
						map_data[i][j] = cin.get();
						lab_data[i][j] = -1;
						targetY = i;	// S[ÌÀW
						targetX = j;
						break;
					}
					else
					{ cin.ignore(); }
				}
			}
		}
		
		int count = 0;
		while(1)
		{
			// u.¨#¨&vÌ(~è¸ÉÚ®Å«é)²ÆÉxt¯
			label(map_data,'.',lab_data,count);
			label(map_data,'#',lab_data,count);
			label(map_data,'&',lab_data,count);
			// &ÉxªÂ¯çê½çI¹
			if(lab_data[targetY][targetX] != -1)
			{ ss << count << endl; break; }
			
			// countÌ×ÚZÉcount+1ðZbg
			for(int i=1; i<hei-1; i++)
			{
				for(int j=1; j<wid-1; j++)
				{
					// xª¢Ýè
					if(lab_data[i][j]==-1)
					{
						// ×ÚZÉcountª êÎ
						if(lab_data[i][j+1]==count || lab_data[i+1][j]==count
						|| lab_data[i][j-1]==count || lab_data[i-1][j]==count)
						{
							// xðÝè·é
							lab_data[i][j] = count+1;
						}
					}
				}
			}
			count++;
		}
	}
	
	cout << ss.str();

	return 0;
}