#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
  int n, m;
  while (cin >> m >> n, m) {
    int sx, sy, d[100][100];
    string field[100];
    for (int i = 0; i < n; i++) {
      cin >> field[i];
      for (int j = 0; j < m; j++) {
        if (field[i][j] == '&') {
          sx = i;
          sy = j;
          d[i][j] = 0;
        } else
          d[i][j] = 1e+9;
      }
    }
    priority_queue<pair<int, pair<int, int> >,
                   vector<pair<int, pair<int, int> > >,
                   greater<pair<int, pair<int, int> > > >
        que;
    que.push(make_pair(0, make_pair(sx, sy)));
    while (!que.empty()) {
      pair<int, pair<int, int> > p = que.top();
      que.pop();
      int cost = p.first, x = p.second.first, y = p.second.second;
      if (d[x][y] < cost) continue;
      for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i], next = d[x][y];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
          if (field[nx][ny] == '#') next++;
          if (d[nx][ny] > next) {
            d[nx][ny] = next;
            que.push(make_pair(next, make_pair(nx, ny)));
          }
        }
      }
    }
    int mi = 1e+9;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (!i || !j || i == n - 1 || j == m - 1) mi = min(mi, d[i][j]);
      }
    }
    cout << mi << endl;
  }
  return 0;
}
