#include <bits/stdc++.h>
using namespace std;

const int MAX = 101;

int W, H;
char G[MAX][MAX];

bool dfs(int x, int y, char from, char to) {
  static int dx[] = {1,0,-1,0};
  static int dy[] = {0,1,0,-1};
  G[y][x] = to;
  bool res = false;
  for(int i = 0; i < 4; ++i) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx < 0 || nx >= W || ny < 0 || ny >= H) {
      res = true;
      continue;
    }
    if(G[ny][nx] != from) continue;
    res |= dfs(nx, ny, from, to);
  }
  return res;
}

int main() {
  while(cin >> W >> H && (W|H)) {
    int sx, sy;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
        if(G[i][j] == '&') {
          sx = j;
          sy = i;
          G[i][j] = '.';
        }
      }
    }
    for(int i = 0; ; ++i) {
      if(dfs(sx, sy, '.', '#')) {
        cout << i << endl;
        break;
      }
      dfs(sx, sy, '#', '.');
    }
  }
  return 0;
}