#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int N = 102;
int h, w;
char mapData[N][N];
int gx, gy;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int height[N][N];
void dfs(int y, int x, int cost) {
  if (mapData[y][x] == '#') ++cost;
  height[y][x] = cost;
  for (int i = 0; i < 4; i++) {
    int ty = y + dy[i];
    int tx = x + dx[i];
    if (ty < 0 || ty >= h) continue;
    if (tx < 0 || tx >= w) continue;
    if (height[ty][tx] <= cost) continue;
    dfs(ty, tx, cost);
  }
}
int solve() {
  fill(height[0], height[N], INF);
  dfs(0, 0, 0);
  return height[gy][gx];
}
int main() {
  while (cin >> w >> h && (h || w)) {
    int i = 0, j;
    for (j = 0; j <= w + 1; j++) {
      mapData[i][j] = '.';
    }
    for (i = 1; i <= h; i++) {
      for (j = 0;; j++) {
        if (j == 0) {
          mapData[i][j] = '.';
          continue;
        }
        if (j == w + 1) {
          mapData[i][j] = '.';
          break;
        }
        cin >> mapData[i][j];
        if (mapData[i][j] == '&') {
          mapData[i][j] = '.';
          gy = i;
          gx = j;
        }
      }
    }
    for (j = 0; j <= w + 1; j++) {
      mapData[i][j] = '.';
    }
    cout << solve() << endl;
  }
  return 0;
}
