#include <bits/stdc++.h>
using namespace std;
void nuru(int y, int x, vector<vector<char> > &v) {
  if (v[y][x] == '#' || v[y][x] == 'x') return;
  v[y][x] = 'x';
  nuru(y - 1, x, v);
  nuru(y + 1, x, v);
  nuru(y, x - 1, v);
  nuru(y, x + 1, v);
}
void nuru2(int y, int x, vector<vector<char> > &v) {
  nuru(y, x, v);
  for (int i = 1; i < v.size() - 1; i++) {
    for (int j = 1; j < v[i].size() - 1; j++) {
      if (v[i][j] == 'x') {
        if (v[i + 1][j] == '#') v[i + 1][j] = 'x';
        if (v[i - 1][j] == '#') v[i - 1][j] = 'x';
        if (v[i][j + 1] == '#') v[i][j + 1] = 'x';
        if (v[i][j - 1] == '#') v[i][j - 1] = 'x';
      }
    }
  }
}
int solve(int n, int m) {
  int gy, gx;
  vector<vector<char> > field(m + 4, vector<char>(n + 4));
  for (int i = 0; i < n + 4; i++) {
    field[0][i] = 'x';
    field[m + 3][i] = 'x';
  }
  for (int i = 0; i < m + 4; i++) {
    field[i][0] = 'x';
    field[i][n + 3] = 'x';
  }
  for (int i = 1; i < n + 3; i++) {
    field[1][i] = '.';
    field[m + 2][i] = '.';
  }
  for (int i = 1; i < m + 3; i++) {
    field[i][1] = '.';
    field[i][n + 2] = '.';
  }
  for (int i = 2; i < m + 2; i++) {
    for (int j = 2; j < n + 2; j++) {
      char c;
      cin >> c;
      field[i][j] = c;
      if (c == '&') {
        gy = i;
        gx = j;
      }
    }
  }
  int ret = 0;
  while (true) {
    int x, y;
    for (int i = 1; i < field.size() - 1; i++) {
      for (int j = 1; j < field[i].size() - 1; j++) {
        if (field[i][j] == '.') {
          y = i;
          x = j;
          goto OUT;
        }
      }
    }
  OUT:
    nuru2(y, x, field);
    if (field[gy][gx] == 'x') return ret;
    ret = ret + 1;
  }
}
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == m && n == 0) break;
    cout << solve(n, m) << endl;
  }
  return 0;
}
