#include <bits/stdc++.h>
using namespace std;
typedef pair<int, pair<int, int> > PP;
int M, N, mv[5] = {-1, 0, 1, 0, -1}, res;
char B[105][105];
int d[105][105];
priority_queue<PP> Q;
void Pset(int y, int x) {
  d[y][x] = 0;
  Q.push(make_pair(0, make_pair(y, x)));
}
int main() {
  for (; scanf("%d%d\n", &N, &M), N + M;) {
    res = 100000000;
    memset(d, 0x7f, sizeof(d));
    for (int i = 0; i < M; i++) gets(B[i]);
    for (int i = 0; i < M; i++) {
      if (B[i][0] == '.') Pset(i, 0);
      if (B[i][N - 1] == '.') Pset(i, N - 1);
    }
    for (int i = 1; i < N - 1; i++) {
      if (B[0][i] == '.') Pset(0, i);
      if (B[M - 1][i] == '.') Pset(M - 1, i);
    }
    while (!Q.empty()) {
      PP tmp = Q.top();
      Q.pop();
      int y = tmp.second.first;
      int x = tmp.second.second;
      int cost = tmp.first;
      if (d[y][x] < cost) continue;
      if (B[y][x] == '&') {
        res = min(res, cost);
        continue;
      }
      for (int i = 0; i < 4; i++) {
        int ny = y + mv[i];
        int nx = x + mv[i + 1];
        if (ny < 0 || ny >= M || nx < 0 || nx >= N) continue;
        int nc = cost + (B[y][x] == '#' && B[ny][nx] != '#');
        if (nc < d[ny][nx]) {
          d[ny][nx] = nc;
          Q.push(make_pair(nc, make_pair(ny, nx)));
        }
      }
    }
    printf("%d\n", res);
  }
}
