#include <bits/stdc++.h>
using namespace std;
int W, H;
char fld[100][101];
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int solve() {
  bool done[100][100] = {{0}};
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 greater<pair<int, pair<int, int> > > >
      Q;
  for (int i = (0); i < ((H)); ++i) {
    if (fld[i][0] != '#')
      Q.push(pair<int, pair<int, int> >(0, pair<int, int>(i, 0)));
    if (fld[i][W - 1] != '#')
      Q.push(pair<int, pair<int, int> >(0, pair<int, int>(i, W - 1)));
  }
  for (int j = (0); j < ((W)); ++j) {
    if (fld[0][j] != '#')
      Q.push(pair<int, pair<int, int> >(0, pair<int, int>(0, j)));
    if (fld[H - 1][j] != '#')
      Q.push(pair<int, pair<int, int> >(0, pair<int, int>(H - 1, j)));
  }
  while (!Q.empty()) {
    pair<int, pair<int, int> > p = Q.top();
    Q.pop();
    if (done[p.second.first][p.second.second]) continue;
    done[p.second.first][p.second.second] = true;
    if (fld[p.second.first][p.second.second] == '&') return p.first;
    for (int i = (0); i < ((4)); ++i) {
      int ty = p.second.first + dy[i], tx = p.second.second + dx[i];
      if (ty < 0 || ty >= H || tx < 0 || tx >= W) continue;
      int tcost = p.first;
      if (fld[p.second.first][p.second.second] == '#' && fld[ty][tx] != '#')
        tcost++;
      Q.push(pair<int, pair<int, int> >(tcost, pair<int, int>(ty, tx)));
    }
  }
}
int main() {
  while (scanf("%d%d", &W, &H), W || H) {
    for (int i = (0); i < ((H)); ++i) scanf("%s", fld[i]);
    printf("%d\n", solve());
  }
  return 0;
}
