#include <iostream>
#include <cstring>
#include <vector>
#include <string>
using namespace std;

int w, h;
int cnt;
char cur;
vector<string> F;

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

bool finish() {
    for (int i = 0; i < w; i++) {
        if (F[0][i] == '&') return true;
        if (F[h-1][i] == '&') return true;
    }
    for (int i = 0; i < h; i++) {
        if (F[i][0] == '&') return true;
        if (F[i][w-1] == '&') return true;
    }
    return false;
}

#define MAX 100
bool used[MAX][MAX];
void dfs(int y, int x) {
    used[y][x] = true;
    F[y][x] = '&';
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && !used[ny][nx] && (F[ny][nx] == cur || F[ny][nx] == '&')) {
            dfs(ny, nx);
        }
    }
}

int main() {
    while (cin >> w >> h, w || h) {
        F.clear(); F.resize(h);
        for (int i = 0; i < h; i++) {
            cin >> F[i];
        }
        int y, x; // &の位置
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (F[i][j] == '&') {
                    y = i;
                    x = j;
                }
            }
        }
        cnt = 0;
        cur = '.';
        while (!finish()) {
            memset(used, 0, sizeof(used));
            dfs(y, x);
            if (cur == '#') {
                cur = '.';
                cnt++;
            } else cur = '#';
        }
        cout << cnt << endl;
    }
    return 0;
}