#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toStr(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<string> field(m);
    pair<int, int> s;
    for (int i = (0); i <= ((m)-1); ++i) {
      cin >> field[i];
      for (int j = (0); j <= ((n)-1); ++j) {
        if (field[i][j] == '&') {
          s.first = i;
          s.second = j;
        }
      }
    }
    queue<pair<int, int> > Q;
    Q.push(s);
    vector<vector<int> > cost(m, vector<int>(n, INF));
    cost[s.first][s.second] = 0;
    int ans = INF;
    while (!Q.empty()) {
      pair<int, int> p = Q.front();
      Q.pop();
      int sy = p.first;
      int sx = p.second;
      int sc = cost[sy][sx];
      for (int d = (0); d <= ((4) - 1); ++d) {
        int ny = sy + dy[d];
        int nx = sx + dx[d];
        int nc = sc;
        if (nx < 0 || n <= nx || ny < 0 || m <= ny) {
          ans = min(ans, sc);
          continue;
        }
        if (field[ny][nx] == '#') {
          nc++;
        }
        if (nc < cost[ny][nx]) {
          cost[ny][nx] = nc;
          Q.push(make_pair(ny, nx));
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
