#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0};
int main() {
  int n, m, i, j, d, res;
  while (scanf("%d%d", &n, &m) && n + m) {
    char cas[128][128];
    int cnt[128][128];
    for ((i) = (0); ((i)) < ((m)); ++(i))
      for ((j) = (0); ((j)) < ((n)); ++(j)) cnt[i][j] = 1 << 30;
    for ((i) = (0); ((i)) < ((m)); ++(i)) scanf("%s", cas[i]);
    int x, y;
    for ((i) = (0); ((i)) < ((m)); ++(i))
      for ((j) = (0); ((j)) < ((n)); ++(j))
        if (cas[i][j] == '&') {
          y = i;
          x = j;
        }
    cnt[y][x] = 0;
    queue<pair<int, int> > q;
    q.push(make_pair(y, x));
    while (!q.empty()) {
      int qsize = (int)q.size();
      for ((i) = (0); ((i)) < ((qsize)); ++(i)) {
        pair<int, int> now = q.front();
        q.pop();
        for ((d) = (0); ((d)) < ((4)); ++(d)) {
          int ny = now.first + dy[d], nx = now.second + dx[d];
          if (ny < 0 || nx < 0 || ny >= m || nx >= n) continue;
          if (cnt[ny][nx] <= cnt[now.first][now.second]) continue;
          if (cas[ny][nx] == '#') {
            cnt[ny][nx] = cnt[now.first][now.second] + 1;
          } else {
            cnt[ny][nx] = cnt[now.first][now.second];
          }
          q.push(make_pair(ny, nx));
        }
      }
    }
    res = 1 << 30;
    for ((i) = (0); ((i)) < ((m)); ++(i)) {
      if (cas[i][0] != '#') res = min(res, cnt[i][0]);
      if (cas[i][n - 1] != '#') res = min(res, cnt[i][0]);
    }
    for ((i) = (0); ((i)) < ((n)); ++(i)) {
      if (cas[0][i] != '#') res = min(res, cnt[0][i]);
      if (cas[m - 1][i] != '#') res = min(res, cnt[0][i]);
    }
    printf("%d\n", res);
  }
  return 0;
}
