#include <bits/stdc++.h>
using namespace std;
int a, b;
string c[100];
int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
vector<pair<int, int> > V;
int main() {
  while (cin >> b >> a, a | b) {
    string f;
    for (int g = 0; g < b + 2; g++) f += ".";
    c[0] = c[a + 1] = f;
    for (int d = 0; d < a; d++) {
      string e;
      cin >> e;
      c[d + 1] = "." + e + ".";
    }
    a += 2;
    b += 2;
    for (int I = 0;; I++) {
      queue<pair<int, int> > Q;
      Q.push(pair<int, int>(0, 0));
      c[0][0] = 0;
      V.push_back(pair<int, int>(0, 0));
      while (Q.size()) {
        pair<int, int> t = Q.front();
        Q.pop();
        for (int i = 0; i < 4; i++) {
          int x = t.first + dx[i], y = t.second + dy[i];
          if (x >= 0 && x < a && y >= 0 && y < b) {
            if (c[x][y] == '.') {
              V.push_back(pair<int, int>(x, y));
              c[x][y] = 0;
              Q.push(pair<int, int>(x, y));
            } else if (c[x][y] == '#') {
              V.push_back(pair<int, int>(x, y));
            } else if (c[x][y] == '&') {
              cout << I << endl;
              goto l;
            }
          }
        }
      }
      for (pair<int, int> o : V) {
        c[o.first][o.second] = '.';
      }
      V.clear();
    }
  l:;
  }
}
