#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, i, j, c, f1, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
  char d[101][101], g[2] = {'.', '#'};
  pair<int, int> a, b;
  stack<pair<int, int>> st[2];
  while (cin >> x >> y) {
    if (x == 0) break;
    for (i = 0; i < y; i++) cin >> d[i];
    c = 0;
    f1 = 0;
    for (i = 0; i < y; i++)
      for (j = 0; j < x; j++)
        if (d[i][j] == '&') {
          a.first = j;
          a.second = i;
          st[0].push(a);
        }
    while (f1 == 0) {
      while (!st[c % 2].empty()) {
        a = st[c % 2].top();
        st[c % 2].pop();
        if (a.first == 0 || a.first == x - 1 || a.second == 0 ||
            a.second == y - 1) {
          f1 = 1;
          continue;
        }
        for (i = 0; i < 4; i++) {
          b.first = a.first + dx[i];
          b.second = a.second + dy[i];
          if (d[b.second][b.first] == g[c % 2]) {
            st[c % 2].push(b);
            d[b.second][a.first] = '&';
          }
          if (d[b.second][b.first] == g[(c + 1) % 2]) {
            st[(c + 1) % 2].push(b);
            d[b.second][a.first] = '&';
          }
        }
      }
      c++;
    }
    while (!st[c % 2].empty()) st[c % 2].pop();
    cout << c / 2 << endl;
  }
  return 0;
}
