#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int G[100 + 2][100 + 2], m, n;
bool dfs(int D[100 + 2][100 + 2], int x, int y, int num) {
  if (x * y == 0 || x == (m + 1) || y == (n + 1)) return true;
  if (G[x][y] == 1 && num == 0) return false;
  if (D[x][y] >= num + 1) return false;
  D[x][y] = num + 1;
  for (int r = 0; r < 4; r++) {
    if (dfs(D, x + dx[r], y + dy[r], (G[x][y] == 0) ? (num) : (num - 1))) {
      return true;
    }
  }
  return false;
}
int main(void) {
  while (cin >> m >> n, m) {
    int sx, sy;
    char c;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> c;
        if (c == '&') {
          G[j][i] = 0;
          sx = j;
          sy = i;
        } else if (c == '#') {
          G[j][i] = 1;
        } else {
          G[j][i] = 0;
        }
      }
    }
    for (int i = 0; i < 1000; i++) {
      int D[100 + 2][100 + 2] = {0};
      if (dfs(D, sx, sy, i)) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
