#include <bits/stdc++.h>
using namespace std;
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));
    for (int i = 0; i < (int)(h); i++) {
      fgets(g[i], sizeof(g[i]), stdin);
      for (int j = 0; j < (int)(w); j++)
        if (g[i][j] == '&') {
          g[i][j] = '.';
          sx = j;
          sy = i;
        }
    }
    priority_queue<pair<int, pair<int, int> >,
                   vector<pair<int, pair<int, int> > >,
                   greater<pair<int, pair<int, int> > > >
        q;
    q.push(make_pair(0, make_pair(sx, sy)));
    while (q.size()) {
      int c = q.top().first;
      int x = q.top().second.first;
      int y = q.top().second.second;
      q.pop();
      if (memo[y][x] != -1) continue;
      if (!((((x)) >= (0) && ((x)) < ((w))) &&
            (((y)) >= (0) && ((y)) < ((h))))) {
        printf("%d\n", c);
        break;
      }
      memo[y][x] = c;
      for (int i = 0; i < (int)(4); i++) {
        int xx = x + _dx[i];
        int yy = y + _dy[i];
        if (memo[yy][xx] != -1) continue;
        if (!((((xx)) >= (0) && ((xx)) < ((w))) &&
              (((yy)) >= (0) && ((yy)) < ((h)))) ||
            g[yy][xx] == '.' || g[yy][xx] == g[y][x])
          q.push(make_pair(c, make_pair(xx, yy)));
        else
          q.push(make_pair(c + 1, make_pair(xx, yy)));
      }
    }
  }
  return 0;
}
