#include <bits/stdc++.h>
using namespace std;
int h, w;
char data[114][514];
int dp[552194];
queue<pair<int, int> > que;
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
int main() {
  int i, j;
  while (cin >> w >> h) {
    int g;
    if (!h) break;
    for (i = 0; i < h; i++) cin >> data[i];
    for (i = 0; i < w * h; i++) dp[i] = 5642194;
    for (i = 0; i < h; i++)
      for (j = 0; j < w; j++) {
        if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
          que.push(pair<int, int>((data[i][j] == '#'), i * w + j));
        if (data[i][j] == '&') g = i * w + j;
      }
    while (!que.empty()) {
      int cost = que.front().first;
      int pos = que.front().second;
      que.pop();
      if (dp[pos] <= cost) continue;
      dp[pos] = cost;
      for (i = 0; i < 4; i++) {
        int ny = pos / w + dy[i];
        int nx = pos % w + dx[i];
        if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
        que.push(pair<int, int>(cost + (data[ny][nx] == '#'), ny * w + nx));
      }
    }
    cout << dp[g] << endl;
  }
  return 0;
}
