#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int main() {
  int n, m;
  while (cin >> n >> m, n | m) {
    char zu[m][n];
    int sx, sy;
    for (int i = 0; i < (int)m; ++i) {
      for (int j = 0; j < (int)n; ++j) {
        cin >> zu[i][j];
        if (zu[i][j] == '&') sx = i, sy = j;
      }
    }
    int dp[m][n];
    memset(dp, -1, sizeof(dp));
    queue<pair<int, int> > Q;
    Q.push(make_pair(sx, sy));
    dp[sx][sy] = 0;
    while (!Q.empty()) {
      int cx = Q.front().first, cy = Q.front().second;
      Q.pop();
      bool cc = false;
      for (int i = 0; i < (int)4; ++i) {
        int nx = cx + dx[i], ny = cy + dy[i];
        if (nx < 0 || nx >= m || ny < 0 || ny >= n) continue;
        if (dp[nx][ny] == -1) {
          if (zu[cx][cy] != '#' && zu[nx][ny] == '#')
            dp[nx][ny] = dp[cx][cy] + 1;
          else
            dp[nx][ny] = dp[cx][cy];
          cc = true;
          Q.push(make_pair(nx, ny));
        }
        if (zu[cx][cy] != '#' && zu[nx][ny] == '#' &&
            dp[nx][ny] > dp[cx][cy] + 1) {
          dp[nx][ny] = dp[cx][cy] + 1;
          Q.push(make_pair(nx, ny));
          cc = true;
        } else if (zu[cx][cy] == zu[nx][ny] && dp[nx][ny] > dp[cx][cy]) {
          dp[nx][ny] = dp[cx][cy];
          Q.push(make_pair(nx, ny));
          cc = true;
        }
        if (zu[cx][cy] == '#' && zu[nx][ny] != '#' &&
            dp[nx][ny] + 1 < dp[cx][cy]) {
          dp[cx][cy] = dp[nx][ny] + 1;
        } else if (zu[cx][cy] == zu[nx][ny] && dp[nx][ny] < dp[cx][cy])
          dp[cx][cy] = dp[nx][ny];
      }
      if (cc) Q.push(make_pair(cx, cy));
    }
    int ans = dp[0][0];
    for (int i = 0; i < (int)n; ++i) {
      ans = min(ans, dp[0][i]);
      ans = min(ans, dp[m - 1][i]);
    }
    for (int i = 0; i < (int)m; ++i) {
      ans = min(ans, dp[i][0]);
      ans = min(ans, dp[i][n - 1]);
    }
    cout << ans << endl;
  }
}
