#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void chmin(T &t, T f) {
  if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
  if (t < f) t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
vector<string> m;
vector<vector<int> > res;
int main() {
  int h, w;
  while (cin >> w >> h, h) {
    m.clear();
    res.clear();
    int i, j;
    vector<int> buf;
    for (i = 0; i < w; i++) buf.push_back(100100100);
    for (i = 0; i < h; i++) {
      string str;
      cin >> str;
      m.push_back(str);
      res.push_back(buf);
    }
    bool update = true;
    int xx[] = {1, -1, 0, 0}, yy[] = {0, 0, 1, -1};
    int k;
    while (update) {
      update = false;
      for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
          if (i == 0 || i == h - 1 || j == 0 || j == w - 1) {
            if (res[i][j] >= 2) {
              res[i][j] = m[i][j] == '#' ? 1 : 0;
              update = true;
            }
          } else if (m[i][j] == '#') {
            for (k = 0; k < 4; k++) {
              if (res[i + yy[k]][j + xx[k]] + 1 < res[i][j]) {
                res[i][j] = res[i + yy[k]][j + xx[k]] + 1;
                update = true;
              }
            }
          } else {
            for (k = 0; k < 4; k++) {
              if (res[i + yy[k]][j + xx[k]] < res[i][j]) {
                res[i][j] = res[i + yy[k]][j + xx[k]];
                update = true;
              }
            }
          }
        }
      }
    }
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        if (m[i][j] == '&') {
          cout << res[i][j] << endl;
        }
      }
    }
  }
  return 0;
}
