#include <bits/stdc++.h>
using namespace std;

constexpr int INF = 1e9;

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector<string> v(m);
        for(int i=0; i<m; ++i) {
            cin >> v[i];
        }

        int sy, sx;
        for(int i=0; i<m; ++i) {
            for(int j=0; j<n; ++j) {
                if(v[i][j] == '&') {
                    sy = i;
                    sx = j;
                }
            }
        }

        using state = tuple<int, int, int>;
        vector<vector<int>> d(m, vector<int>(n, INF));
        priority_queue<state, vector<state>, greater<state>> que;
        d[sy][sx] = 0;
        que.push(make_tuple(0, sy, sx));
        int dx[4] = {0, 1, 0, -1},
            dy[4] = {1, 0, -1, 0};
        int res = INF;
        while(!que.empty()) {
            int cur, y, x;
            tie(cur, y, x) = que.top();
            que.pop();
            if(d[y][x] < cur) {
                continue;
            }
            for(int i=0; i<4; ++i) {
                int ny = y + dy[i], nx = x + dx[i];
                if(ny < 0 || m <= ny || nx < 0 || n <= nx) {
                    res = min(res, d[y][x]);
                    continue;
                }
                if(d[ny][nx] > d[y][x] + ((v[y][x] == '.' || v[y][x] == '&') && v[ny][nx] == '#')) {
                    d[ny][nx] = d[y][x] + ((v[y][x] == '.' || v[y][x] == '&') && v[ny][nx] == '#');
                    que.push(make_tuple(d[ny][nx], ny, nx));
                }
            }
        }
        cout << res << endl;
    }
}
