#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int main() {
  int cost[102][102];
  char geo[102][102];
  deque<pair<int, int> > dq;
  pair<int, int> a, b;
  int n, m;
  while (cin >> n >> m, n | m) {
    dq.clear();
    fill_n((char*)geo, 102 * 102, '.');
    fill_n((int*)cost, 102 * 102, (1 << 29));
    for (int y = 1; y <= m; y++) {
      for (int x = 1; x <= n; x++) cin >> geo[y][x];
    }
    for (int y = 1; y <= m; y++) {
      cost[y][0] = cost[y][n] = 0;
      dq.push_back(make_pair(y, 0));
      dq.push_back(make_pair(y, n));
    }
    for (int x = 2; x < n; x++) {
      cost[0][x] = cost[m][x] = 0;
      dq.push_back(make_pair(0, x));
      dq.push_back(make_pair(m, x));
    }
    int ans;
    while (!dq.empty()) {
      a = dq.front();
      dq.pop_front();
      for (int i = 0; i < 4; i++) {
        b.first = a.first + dy[i];
        b.second = a.second + dx[i];
        int c = 0;
        if (geo[a.first][a.second] == '#' && geo[b.first][b.second] == '.')
          c = 1;
        if (b.first <= 0 || m < b.first || b.second <= 0 || n < b.second)
          continue;
        if (geo[b.first][b.second] == '&') {
          ans = c + cost[a.first][a.second];
          goto FIND;
        }
        if (c + cost[a.first][a.second] < cost[b.first][b.second]) {
          if (c == 1) {
            cost[b.first][b.second] = 1 + cost[a.first][a.second];
            dq.push_back(b);
          } else {
            cost[b.first][b.second] = cost[a.first][a.second];
            dq.push_front(b);
          }
        }
      }
    }
  FIND:
    cout << ans << endl;
  }
}
