import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

bool canGoal(bool[][] checked, ref char[][] c, int x, int y) {
    if(checked[x][y]) {
        return false;
    }
    checked[x][y] = true;
    if(x == 0 || y == 0 || x == c.length-1 || y == c[0].length-1) {
        return true;
    }

    auto dx = [1, 0, -1, 0];
    auto dy = [0, 1, 0, -1];
    foreach(i; iota(4)) {
        auto nx = x + dx[i];
        auto ny = y + dy[i];
        if(c[nx][ny] == '#') {
            continue;
        }
        if(canGoal(checked, c, nx, ny)) {
            return true;
        }
    }
    return false;
}

void goOver(ref char[][] c, int x, int y) {
    auto dx = [1, 0, -1, 0];
    auto dy = [0, 1, 0, -1];

    c[x][y] = 'g';

    void fill(int x, int y) {
        if(c[x][y] != '#') {
            return;
        }

        c[x][y] = 'g';

        foreach(i; iota(4)) {
            auto nx = x + dx[i];
            auto ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= c.length || ny >= c[0].length) {
                continue;
            }
            fill(nx, ny);
        }
    }

    foreach(i; iota(4)) {
        auto nx = x + dx[i];
        auto ny = y + dy[i];
        if(nx < 0 || ny < 0 || nx >= c.length || ny >= c[0].length) {
            continue;
        }
        if(c[nx][ny] == '#') {
            fill(nx, ny);
        }
        if(c[nx][ny] == '.') {
            goOver(c, nx, ny);
        }
    }
}

void recover(ref char[][] c) {
    foreach(ref ci; c) {
        foreach(ref cii; ci) {
            if(cii == 'g') {
                cii = '.';
            }
        }
    }
}

void main(){
    while(true) {
        int n, m;
        readlnTo(n, m);
        if(n == 0) {
            return;
        }
        char[][] c;
        foreach(i; iota(m)) {
            c ~= readln().chomp().to!(char[]);
        }
        int sx, sy;
        foreach(i; iota(m)) {
            foreach(j; iota(n)) {
                if(c[i][j] == '&') {
                    sx = i;
                    sy = j;
                }
            }
        }
        int ans;
        while(!canGoal(new bool[][](m, n), c, sx, sy)){
            ++ans;
            goOver(c, sx, sy);
            recover(c);
        }
        writeln(ans);
    }
}