#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

typedef int cost_type;
struct edge {
	int to;
	cost_type cost;
	edge(){}
	edge(int to,cost_type cost) : to(to) ,cost(cost) {}
};

typedef pair<cost_type,int> P;

void dijkstra(int s,vector<P::first_type>& cost_table,vector<vector<edge> >& edges,vector<int>* _prev = NULL){
	
	//init
	cost_table.resize((int)edges.size());
	fill(cost_table.begin(),cost_table.end(),P::first_type(INF));
	if(_prev) _prev->resize((int)edges.size());
	if(_prev) fill(_prev->begin(),_prev->end(),-1);
	
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(0,s));
	cost_table[s] = 0;

	while(!q.empty()){
		P p = q.top(); q.pop();
		int v = p.second;
		if(cost_table[v] < p.first) continue;
		for(int i = 0; i < (int)edges[v].size(); i++){
			edge& e = edges[v][i];
			if(cost_table[e.to] > cost_table[v] + e.cost){
				cost_table[e.to] = cost_table[v] + e.cost;
				if(_prev) (*_prev)[e.to] = v;
				q.push(P(cost_table[e.to],e.to));
			}
		}
	}
}

int main(){
	int n,m;
	while(cin>>n>>m,(n||m)){
		vector<string> v(m);
		FOR(i,m) cin>>v[i];
		vector<vector<edge> >e(n*m);
		int start;
		FOR(i,m) FOR(j,n){
			if(v[i][j] == '&'){
				start = i * n + j;
			}
			static int dx[] = {0,0,1,-1};
			static int dy[] = {1,-1,0,0};
			FOR(k,4){
				int nh = dx[k] + i;
				int nw = dy[k] + j;
				if(nh < 0 || nh >= m || nw <0 || nw >= n) continue;
				int nx = nh * n + nw;
				int ct = v[i][j] != '#' && v[nh][nw] == '#';
				e[i * n + j].push_back(edge(nx,ct));
			}
		}

		vector<int> cost;
		dijkstra(start,cost,e);

		int ans = INF;
		FOR(i,m) FOR(j,n){
			if(i == 0 || i == m-1 || j == 0 || j == n-1){
				ans = min(ans,cost[i*n+j]);
			}
		}

		cout << ans << endl;

	}

	return 0;
}