#include <bits/stdc++.h>
using namespace std;
int a, b;
string c[102];
vector<int> l, r, x, y;
int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
bool S;
void saiki(int n, int m) {
  c[n][m] = 0;
  for (int i = 0; i < 4; i++) {
    int p = n + dx[i], q = m + dy[i];
    if (p >= 0 && p < a && q >= 0 && q < b) {
      if (c[p][q] == '&')
        S = true;
      else if (c[p][q] == '.') {
        saiki(p, q);
      } else if (c[p][q] == '#') {
        l.push_back(p);
        r.push_back(q);
      }
    }
  }
}
int main() {
  while (cin >> b >> a, a | b) {
    string t;
    for (int q = 0; q < b + 2; q++) t += ".";
    c[0] = c[a + 1] = t;
    for (int d = 0; d < a; d++) {
      string e;
      cin >> e;
      c[d + 1] = "." + e + ".";
    }
    l.clear();
    r.clear();
    x.clear();
    y.clear();
    saiki(0, 0);
    for (int f = 0;; f++) {
      if (S) {
        cout << f << endl;
        break;
      }
      x = l;
      y = r;
      l.clear();
      r.clear();
      for (int i = 0; i < x.size(); i++) {
        c[x[i]][y[i]] = ',';
      }
      for (int i = 0; i < x.size(); i++) {
        saiki(x[i], y[i]);
      }
    }
  }
}
