#include <bits/stdc++.h>
using namespace std;
int f(int a[][100], int b[][100], int x, int y, int m, int n, int c) {
  int mn = 100;
  if (x == 0 || x == m - 1 || y == 0 || y == n - 1) {
    if (a[x][y])
      return c + 1;
    else
      return c;
  }
  if (b[x][y] == -1) {
    if (a[x][y])
      b[x][y] = c + 1;
    else {
      b[x][y] = c;
      int tmp;
      if ((tmp = f(a, b, x - 1, y, m, n, c)) >= 0) mn = min(mn, tmp);
      if ((tmp = f(a, b, x, y - 1, m, n, c)) >= 0) mn = min(mn, tmp);
      if ((tmp = f(a, b, x + 1, y, m, n, c)) >= 0) mn = min(mn, tmp);
      if ((tmp = f(a, b, x, y + 1, m, n, c)) >= 0) mn = min(mn, tmp);
      if (mn != 100) return mn;
    }
  }
  return -1;
}
int main() {
  int i, j, k;
  int a[100][100], b[100][100], mn, x, y, m, n;
  string s;
  for (;;) {
    cin >> m >> n;
    if (m + n == 0) break;
    memset(a, 0, sizeof(a));
    memset(b, -1, sizeof(b));
    for (i = 0; i < n; i++) {
      cin >> s;
      for (j = 0; j < m; j++) {
        if (s[j] == '#')
          a[j][i] = 1;
        else if (s[j] == '&') {
          x = j;
          y = i;
          b[x][y] = 0;
        }
      }
    }
    if (x == 0 || x == m - 1 || y == 0 || y == n - 1)
      mn = 0;
    else {
      for (i = 0;; i++) {
        mn = 100;
        for (j = 0; j < m; j++) {
          for (k = 0; k < n; k++) {
            if (b[j][k] == i) {
              int tmp;
              if ((tmp = f(a, b, j - 1, k, m, n, i)) >= 0) mn = min(mn, tmp);
              if ((tmp = f(a, b, j, k - 1, m, n, i)) >= 0) mn = min(mn, tmp);
              if ((tmp = f(a, b, j + 1, k, m, n, i)) >= 0) mn = min(mn, tmp);
              if ((tmp = f(a, b, j, k + 1, m, n, i)) >= 0) mn = min(mn, tmp);
            }
          }
        }
        if (mn != 100) break;
      }
    }
    cout << mn << endl;
  }
  return 0;
}
