#include <iostream>
#include <algorithm>
using namespace std;

const int MAX_N = 101;
int w, h;
char G[MAX_N][MAX_N];

bool dfs(int x, int y, char c) {
  bool isOver = (x==0||x==w-1||y==0||y==h-1);
  G[y][x] = c;
  for(int d = -1; d <= 1; d += 2) {
    for(int i = 0; i < 2; ++i) {
      int nx = x;
      int ny = y;
      if(i) nx += d;
      else  ny += d;
      if(nx < 0 || nx >= w) continue;
      if(ny < 0 || ny >= h) continue;
      if(G[ny][nx] == c) continue;
      isOver = isOver || dfs(nx,ny,c);
    }
  }
  return isOver;
}

int solve(int x, int y) {
  int t;
  for(t = 0; !dfs(x,y,'#'); dfs(x,y,'.'),++t);
  return t;
}

int main() {
  while(cin >> w >> h && (w|h)) {
    int x, y;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
	cin >> G[i][j];
	if(G[i][j] == '&') {
	  x = j;
	  y = i;
	  G[i][j] = '.';
	}
      }
    }
    cout << solve(x,y) << endl;
  }
  return 0;
}