#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

typedef vector <string> VS;
typedef vector <int> VI;
typedef vector <VI> VVI;

const int inf = 1<<24;

typedef pair <int, int> PII;
typedef pair <int, PII> Node;
typedef priority_queue <Node, vector<Node>, greater<Node> > Queue;

const int dr[4] = { 0, 0, 1, -1 };
const int dc[4] = { 1, -1, 0, 0 };

int main() {
    int n, m;
    while ( cin >> n >> m ) {
        if ( n == 0 && m == 0 ) break;

        VS lines(m);
        for ( int i = 0; i < m; i++ ) {
            cin >> lines[i];
        }
        VVI O(m, VI(n, inf));
        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                O[i][j] = lines[i][j] == '#' ? 1 : 0;
            }
        }
        int sr, sc;
        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                if ( lines[i][j] == '&' ) {
                    sr = i;
                    sc = j;
                }
            }
        }

        VVI D(m, VI(n, inf));
        Queue Q;
        Node start( 0, PII( sr, sc ) );
        Q.push( start );
        D[sr][sc] = 0;

        while ( !Q.empty() ) {
            Node node = Q.top();
            Q.pop();

            int cost = node.first;
            int r = node.second.first;
            int c = node.second.second;

            if ( r == 0 || r == m-1 || c == 0 || c == n-1 ) {
                cout << cost << endl;
                break;
            }

            for ( int i = 0; i < 4; i++ ) {
                int nr = r + dr[i];
                int nc = c + dc[i];
                if ( nr < 0 || nr >= m || nc < 0 || nc >= n ) continue;
                int ncost = cost + ( !O[r][c] && O[nr][nc] ? 1 : 0 );
                if ( ncost >= D[nr][nc] ) continue;
                D[nr][nc] = ncost;
                Node nnode( ncost, PII( nr, nc ) );
                Q.push( nnode );
            }
        }
    }
    return 0;
}