#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++)

typedef pair<int, int> i_i;
bool dfs(int x, int y, char a, char b, 
        vector<vector<char> > &g);

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int h, w;

int main()
{
    while (cin >> w >> h, (w|h)) {
        vector<vector<char> > g(h, vector<char>(w));
        int sx, sy, cnt = 0;
        loop(i, h) {
            loop(j, w) {
                cin >> g[i][j];
                if (g[i][j] == '&') {
                    sx = i;
                    sy = j;
                    g[i][j] = '.';
                }
            }
        }
        while (!dfs(sx, sy, '.', '#', g)) {
            cnt++;
            dfs(sx, sy, '#', '.', g);
        }
        cout << cnt << endl;
    }
    return 0;
}

bool dfs(int x, int y, char a, char b, 
        vector<vector<char> > &g) {
    bool ret = false;
    g[x][y] = b;
    for (int i = 0; i < 4; i++) {
        if (x+dx[i] < 0 || y+dy[i] < 0 || 
            h <= x+dx[i] || w <= y+dy[i] ) {
            return true;
        }
        if (g[x+dx[i]][y+dy[i]] == a) {
            ret = dfs(x+dx[i], y+dy[i], a, b, g);
        }
    }
    return ret;
}