#include <bits/stdc++.h>
using namespace std;
void label(vector<vector<char> >& dt, char sdt, vector<vector<int> >& lb,
           int slb) {
  int h = dt.size();
  int w = dt[0].size();
  bool flag;
  do {
    flag = false;
    for (int i = 1; i < h - 1; i++) {
      for (int j = 1; j < w - 1; j++) {
        if (dt[i][j] == sdt && lb[i][j] == -1) {
          if (lb[i][j + 1] == slb || lb[i + 1][j] == slb ||
              lb[i][j - 1] == slb || lb[i - 1][j] == slb) {
            lb[i][j] = slb;
            flag = true;
          }
        }
      }
    }
  } while (flag);
  return;
}
int main() {
  stringstream ss;
  int wid, hei, tmp, targetX, targetY;
  while (1) {
    cin >> wid >> hei;
    if (wid == 0 && hei == 0) {
      break;
    }
    wid += 2;
    hei += 2;
    vector<vector<char> > map_data(hei, vector<char>(wid));
    vector<vector<int> > lab_data(hei, vector<int>(wid));
    for (int i = 0; i < hei; i++)
      for (int j = 0; j < wid; j++) {
        map_data[i][j] = '.';
        lab_data[i][j] = 0;
      }
    for (int i = 1; i < hei - 1; i++) {
      for (int j = 1; j < wid - 1; j++) {
        while (1) {
          char pk = cin.peek();
          if (pk == '.' || pk == '#') {
            map_data[i][j] = cin.get();
            lab_data[i][j] = -1;
            break;
          } else if (pk == '&') {
            map_data[i][j] = cin.get();
            lab_data[i][j] = -1;
            targetY = i;
            targetX = j;
            break;
          } else {
            cin.ignore();
          }
        }
      }
    }
    int count = 0;
    while (1) {
      label(map_data, '.', lab_data, count);
      label(map_data, '#', lab_data, count);
      label(map_data, '&', lab_data, count);
      if (lab_data[targetY][targetX] != -1) {
        ss << count << endl;
        break;
      }
      for (int i = 1; i < hei - 1; i++) {
        for (int j = 1; j < wid - 1; j++) {
          if (lab_data[i][j] == -1) {
            if (lab_data[i][j + 1] == count || lab_data[i + 1][j] == count ||
                lab_data[i][j - 1] == count || lab_data[i - 1][j] == count) {
              lab_data[i][j] = count + 1;
            }
          }
        }
      }
      count++;
    }
  }
  cout << ss.str();
  return 0;
}
