#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1 << 30;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
bool dp[110][110][150] = {0};
int main() {
  int n, m;
  while (cin >> m >> n, n + m) {
    vector<string> in(n);
    for (int i = 0; i < n; i++) cin >> in[i];
    queue<pair<int, pair<int, int> > > q;
    for (int i = 0; i < 110; i++)
      for (int j = 0; j < 110; j++)
        for (int k = 0; k < 150; k++) dp[i][j][k] = false;
    bool h = false;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
          if (in[i][j] == '&') h = true;
          if (in[i][j] != '#')
            q.push(pair<int, pair<int, int> >(i, pair<int, int>(j, 0)));
        }
    if (h) {
      cout << 0 << endl;
      continue;
    }
    int out = inf;
    while (!q.empty()) {
      pair<int, pair<int, int> > p = q.front();
      q.pop();
      int x = p.first, y = p.second.first, cost = p.second.second;
      for (int k = 0; k < 4; k++) {
        int nx = x + dx[k], ny = y + dy[k];
        if (nx < 0 || ny < 0 || nx >= n || ny >= m) continue;
        int ncost = cost + (in[nx][ny] == '#' ? 1 : 0);
        if (in[nx][ny] == '&') {
          out = min(out, ncost);
        }
        if (dp[nx][ny][ncost] == 0) {
          dp[nx][ny][ncost] = true;
          q.push(pair<int, pair<int, int> >(nx, pair<int, int>(ny, ncost)));
        }
      }
    }
    cout << out << endl;
  }
}
