#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}


int main(){
  int h,w;
  char g[128][128];

  while(scanf("%d%d ",&w,&h), w+h){
    int memo[128][128];
    int sx, sy;

    memset(memo, -1, sizeof(memo));

    REP(i,h){
      fgets(g[i], sizeof(g[i]), stdin);
      REP(j,w) if(g[i][j] == '&'){
        g[i][j] = '.';
        sx = j;
        sy = i;
      }
    }

    typedef pair<int, pair<int,int> > data;
    priority_queue<data,vector<data>,greater<data> > q;

    q.push(mp(0,mp(sx,sy)));

    while(q.size()){
      int c = q.top().f;
      int x = q.top().s.f;
      int y = q.top().s.s;

      //printf("%d,%d => %d\n",x,y,c);

      q.pop();

      if(memo[y][x] != -1) continue;

      if(!ISIN(x,y,w,h)){
        print(c);
        break;
      }

      memo[y][x] = c;

      REP(i,4){
        int xx = x + _dx[i];
        int yy = y + _dy[i];

        if(memo[yy][xx] != -1) continue;

        if(!ISIN(xx,yy,w,h) || g[yy][xx] == '.' || g[yy][xx] == g[y][x])
          q.push(mp(c,mp(xx,yy)));
        else
          q.push(mp(c+1,mp(xx,yy)));
      }
    }
  }

  return 0;
}