#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<vector<int> > cnt(m, vector<int>(n, (1 << 29)));
    vector<string> str(m);
    for (int i = (0); i < (m); i++) cin >> str[i];
    priority_queue<pair<int, pair<int, int> >,
                   vector<pair<int, pair<int, int> > >,
                   greater<pair<int, pair<int, int> > > >
        pq;
    for (int i = (0); i < (m); i++) {
      pq.push(make_pair(str[i][0] == '#', pair<int, int>(i, 0)));
      pq.push(make_pair(str[i][n - 1] == '#', pair<int, int>(i, n - 1)));
    }
    for (int i = (0); i < (n); i++) {
      pq.push(make_pair(str[0][i] == '#', pair<int, int>(0, i)));
      pq.push(make_pair(str[m - 1][i] == '#', pair<int, int>(m - 1, i)));
    }
    while (!pq.empty()) {
      pair<int, pair<int, int> > now = pq.top();
      pq.pop();
      int x = now.second.second, y = now.second.first;
      if (cnt[y][x] != (1 << 29)) continue;
      cnt[y][x] = now.first;
      int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
      for (int i = (0); i < (4); i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (!(nx >= 0 && nx < n && ny >= 0 && ny < m)) continue;
        pq.push(make_pair(cnt[y][x] + (str[ny][nx] == '#'),
                          pair<int, int>(ny, nx)));
      }
    }
    int gx, gy;
    for (int i = (0); i < (m); i++)
      for (int j = (0); j < (n); j++)
        if (str[i][j] == '&') gx = j, gy = i;
    cout << cnt[gy][gx] << endl;
  }
  return 0;
}
