#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;
}
char mt[110][110];
int res[110][110];
int main() {
  int n, m;
  while (n = in(), m = in()) {
    int i, j;
    for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        cin >> mt[i][j];
        res[i][j] = 1000000000;
      }
    }
    int k;
    for (k = 0; k < n * m; k++) {
      for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++) {
          if (i == 0 || j == 0 || i == m - 1 || j == n - 1) {
            if (mt[i][j] == '#')
              res[i][j] = 1;
            else
              res[i][j] = 0;
          } else {
            int p;
            int xx[] = {1, -1, 0, 0};
            int yy[] = {0, 0, 1, -1};
            for (p = 0; p < 4; p++) {
              if (0 <= i + yy[p] && i + yy[p] < m && 0 <= j + xx[p] &&
                  j + xx[p] < n) {
                if (mt[i][j] == '#')
                  chmin(res[i][j], res[i + yy[p]][j + xx[p]] + 1);
                else
                  chmin(res[i][j], res[i + yy[p]][j + xx[p]]);
              }
            }
          }
        }
      }
    }
    for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        if (mt[i][j] == '&') cout << res[i][j] << endl;
      }
    }
  }
  return 0;
}
