#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int main(void) {
  int n, m;
  while (cin >> m) {
    cin >> n;
    if ((m | n) == 0) break;
    char field[n][m];
    int step[n][m];
    bool visited[n][m];
    string str;
    int x, y;
    deque<pair<pair<int, int>, int> > q;
    memset(step, -1, sizeof(step));
    memset(visited, false, sizeof(visited));
    for (int i = 0; i < n; i++) {
      cin >> str;
      for (int j = 0; j < m; j++) {
        field[i][j] = str[j];
        if (str[j] == '&') {
          x = i;
          y = j;
          field[i][j] = '.';
        }
      }
    }
    pair<int, int> pos;
    int num;
    q.push_back(make_pair(make_pair(x, y), 0));
    while (1) {
      if (q.empty()) {
        bool ended = true;
        for (int i = 0; i < n; i++) {
          for (int j = 0; j < m; j++) {
            if (!visited[i][j]) ended = false;
          }
        }
        if (ended) {
          int ret = 100000;
          for (int i = 0; i < n; i++) {
            ret = min(ret, step[i][0]);
            ret = min(ret, step[i][m - 1]);
          }
          for (int i = 0; i < m; i++) {
            ret = min(ret, step[0][i]);
            ret = min(ret, step[n - 1][i]);
          }
          cout << ret << endl;
          break;
        } else {
          bool find = false;
          for (int i = 0; i < n && !find; i++) {
            for (int j = 0; j < m && !find; j++) {
              if (!visited[i][j]) {
                int tmpstep = 100000;
                for (int k = 0; k < 4; k++) {
                  if (0 <= i + dx[k] && i + dx[k] <= n - 1 && 0 <= j + dy[k] &&
                      j + dy[k] <= m - 1) {
                    if (visited[i + dx[k]][j + dy[k]]) {
                      tmpstep = min(tmpstep, step[i + dx[k]][j + dy[k]]);
                    }
                  }
                }
                if (tmpstep != 100000) {
                  if (field[i][j] == '.') {
                    q.push_back(make_pair(make_pair(i, j), tmpstep));
                  } else {
                    q.push_back(make_pair(make_pair(i, j), tmpstep + 1));
                  }
                  find = true;
                }
              }
            }
          }
        }
      }
      pos = q.front().first;
      x = pos.first;
      y = pos.second;
      num = q.front().second;
      q.pop_front();
      step[x][y] = num;
      visited[x][y] = true;
      for (int i = 0; i < 4; i++) {
        if (0 <= x + dx[i] && x + dx[i] <= n - 1 && 0 <= y + dy[i] &&
            y + dy[i] <= m - 1) {
          if (field[x][y] == field[x + dx[i]][y + dy[i]]) {
            if (!visited[x + dx[i]][y + dy[i]] &&
                find(q.begin(), q.end(),
                     make_pair(make_pair(x + dx[i], y + dy[i]), num)) ==
                    q.end()) {
              q.push_back(make_pair(make_pair(x + dx[i], y + dy[i]), num));
            }
          }
        }
      }
    }
  }
}
