#include <bits/stdc++.h>
int p[11500], rank[11500];
void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
  if (rank[x] > rank[y])
    p[y] = x;
  else {
    p[x] = y;
    if (rank[x] == rank[y]) rank[y] = rank[y] + 1;
  }
}
int find_set(int x) {
  if (x != p[x]) p[x] = find_set(p[x]);
  return p[x];
}
void union_set(int x, int y) { link(find_set(x), find_set(y)); }
typedef struct {
  char c;
  int x;
} T;
T map[105 + 5][105 + 5];
int R, C;
int gr, gc;
void lnk(int r1, int c1, int r2, int c2) {
  union_set(map[r1][c1].x, map[r2][c2].x);
}
int node[3000], len;
int dis[3000][3000];
int f[11500];
int s, g;
char visited[3000 + 2];
int total[3000 + 2];
int search(int n, int s, int g) {
  int i, j, next, min;
  for (i = 0; i < n; i++) visited[i] = 0, total[i] = 100000;
  total[s] = 0, next = s;
  do {
    i = next, visited[i] = 1, min = 100000;
    for (j = 0; j < n; j++) {
      if (visited[j]) continue;
      if (dis[i][j] > 0 && total[i] + dis[i][j] < total[j]) {
        total[j] = total[i] + dis[i][j];
      }
      if (total[j] < min) min = total[j], next = j;
    }
  } while (min < 100000);
  return total[g];
}
int main() {
  int r, c, r2, c2, k, cc, x1, x2;
  char buf[105];
  int mv[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  while (scanf("%d%d", &C, &R) && C) {
    for (r = 1; r <= R; r++) {
      scanf("%s", buf);
      for (c = 1; c <= C; c++) map[r][c].c = buf[c - 1];
    }
    R += 2, C += 2;
    for (r = 0; r < R; r++) map[r][0].c = map[r][C - 1].c = '.';
    for (c = 0; c < C; c++) map[0][c].c = map[R - 1][c].c = '.';
    for (k = r = 0; r < R; r++)
      for (c = 0; c < C; c++) map[r][c].x = k, make_set(k++);
    for (r = 0; r < R; r++) lnk(r, 0, 0, 0), lnk(r, C - 1, 0, 0);
    for (c = 0; c < R; c++) lnk(0, c, 0, 0), lnk(R - 1, c, 0, 0);
    R--, C--;
    for (r = 1; r < R; r++)
      for (c = 1; c < C; c++) {
        if (map[r][c].c == '&') gr = r, gc = c;
        cc = map[r][c].c;
        for (k = 0; k < 4; k++) {
          r2 = r + mv[k][0], c2 = c + mv[k][1];
          if (map[r2][c2].c == cc) lnk(r2, c2, r, c);
        }
      }
    for (k = 0; k < 4; k++) {
      r2 = gr + mv[k][0], c2 = gc + mv[k][1];
      if (map[r2][c2].c == '.') lnk(r2, c2, gr, gc);
    }
    if (p[map[0][0].x] == p[map[gr][gc].x]) {
      puts("0");
      continue;
    }
    memset(f, -1, sizeof(f));
    memset(dis, -1, sizeof(dis));
    for (len = 0, r = 0; r <= R; r++)
      for (c = 0; c <= C; c++) {
        x1 = p[map[r][c].x];
        if (f[x1] < 0) f[x1] = len, node[len++] = x1;
      }
    for (r = 1; r <= R; r++)
      for (c = 1; c < C; c++) {
        for (k = 0; k < 4; k++) {
          r2 = r + mv[k][0], c2 = c + mv[k][1];
          if (map[r][c].x != map[r2][c2].x) {
            x1 = f[p[map[r][c].x]], x2 = f[p[map[r2][c2].x]];
            dis[x1][x2] = dis[x2][x1] = 1;
          }
        }
      }
    k = search(len, f[p[map[0][0].x]], f[p[map[gr][gc].x]]);
    if (k & 1) k++;
    printf("%d\n", k >> 1);
  }
  return 0;
}
