#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int n,m,flag,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
char c[100][100];

void paint(int x,int y,char ch){
	c[y][x]='o';
	rep(i,4){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>=0&&nx<n&&ny>=0&&ny<m){
			if(c[ny][nx]==ch)paint(nx,ny,ch);
			if(c[ny][nx]=='&')flag=1;
		}
	}
}

int main(){
	while(cin>>n>>m&&n){
		flag=0;
		rep(i,m)rep(j,n){
			cin>>c[i][j];
			if(i==0||i==m-1||j==0||j==n-1){
				if(c[i][j]=='.')c[i][j]='o';
				if(c[i][j]=='&')flag=1;
			}
		}
		int t=0;
		while(!flag){
			if(t==1)c[0][0]='o';
			if(t)rep(i,m)rep(j,n)if(c[i][j]=='o')paint(j,i,'#');
			rep(i,m)rep(j,n)if(c[i][j]=='o')paint(j,i,'.');
			if(!flag)t++;
		}
		cout<<t<<endl;
	}
}