#include <bits/stdc++.h>
using namespace std;
const int dir[][2] = {1, 0, 0, 1, -1, 0, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (true) {
    int w, h;
    cin >> w >> h;
    if (!(w | h)) {
      break;
    }
    vector<string> board(h);
    for (auto &line : board) {
      cin >> line;
    }
    int sy, sx;
    for (int i = (int)(0); i < (int)(h); ++i) {
      for (int j = (int)(0); j < (int)(w); ++j) {
        if (board[i][j] == '&') {
          sy = i;
          sx = j;
        }
      }
    }
    vector<vector<int> > cost(h, vector<int>(w, INT_MAX));
    cost[sy][sx] = 0;
    queue<pair<int, int> > que;
    que.push(make_pair((sy), (sx)));
    while (!que.empty()) {
      auto cur = que.front();
      que.pop();
      for (int d = (int)(0); d < (int)(4); ++d) {
        auto next = cur;
        next.first += dir[d][0];
        next.second += dir[d][1];
        if (!(0 <= next.first && next.first < h && 0 <= next.second &&
              next.second < w)) {
          continue;
        }
        int nextcost = cost[cur.first][cur.second] +
                       (board[cur.first][cur.second] == '.' &&
                        board[next.first][next.second] == '#');
        if (cost[next.first][next.second] <= nextcost) {
          continue;
        }
        cost[next.first][next.second] = nextcost;
        que.push(next);
      }
    }
    int res = INT_MAX;
    for (int i = (int)(0); i < (int)(w); ++i) {
      res = min(res, min(cost[0][i], cost[h - 1][i]));
    }
    for (int i = (int)(0); i < (int)(h); ++i) {
      res = min(res, min(cost[i][0], cost[i][w - 1]));
    }
    cout << res << endl;
  }
  return 0;
}
