#include <bits/stdc++.h>
using namespace std;
class Pox {
 public:
  pair<int, int> p;
  int cost;
  Pox(pair<int, int> p = pair<int, int>(0, 0), int cost = 0)
      : p(p), cost(cost) {}
};
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int h, w;
void print(vector<vector<char> > G) {
  cout << "---print---" << endl;
  for (int i = 0; i < G.size(); i++) {
    for (int j = 0; j < G[i].size(); j++) cout << G[i][j];
    cout << endl;
  }
  cout << endl;
}
void draw(vector<vector<char> >& G, pair<int, int> p) {
  for (int i = 0; i < 4; i++) {
    int nx = p.first + dx[i];
    int ny = p.second + dy[i];
    if (!(1 <= ny && ny <= h && 1 <= nx && nx <= w)) continue;
    if (G[ny][nx] == '&' || G[ny][nx] == '#') continue;
    G[ny][nx] = '&';
    draw(G, pair<int, int>(nx, ny));
  }
}
int main() {
  while (cin >> w >> h, (w || h)) {
    cerr << w << " " << h << endl;
    vector<vector<char> > G;
    pair<int, int> ed;
    G.resize(h + 2);
    deque<Pox> deq;
    int mincost[h + 3][w + 3];
    for (int i = 0; i <= h + 1; i++) {
      G[i].resize(w + 2);
      string line;
      if (i == 0 || i == h + 1)
        line = string(h + 2, '.');
      else
        cin >> line;
      cerr << line << endl;
      for (int j = 0; j <= w + 1; j++) {
        mincost[i][j] = (1 << 28);
        if (i == 0 || j == 0 || i == h + 1 || j == w + 1) {
          G[i][j] = '.';
          deq.push_back(Pox(pair<int, int>(j, i), 0));
          mincost[i][j] = 0;
          continue;
        }
        G[i][j] = line[j - 1];
        if (G[i][j] == '&') ed = pair<int, int>(j, i);
      }
    }
    draw(G, ed);
    int men = (1 << 28);
    while (!deq.empty()) {
      Pox pox = deq.front();
      deq.pop_front();
      pair<int, int> p = pox.p;
      int cost = pox.cost;
      if (G[p.second][p.first] == '&') {
        men = min(men, cost);
        break;
      }
      for (int i = 0; i < 4; i++) {
        int nx = p.first + dx[i];
        int ny = p.second + dy[i];
        if (!(1 <= nx && nx <= w && 1 <= ny && ny <= h)) continue;
        int d = G[ny][nx] == '#' ? 1 : 0;
        if (mincost[ny][nx] > cost + d) {
          mincost[ny][nx] = cost + d;
          deq.push_back(Pox(pair<int, int>(nx, ny), mincost[ny][nx]));
        }
      }
    }
    cout << men << endl;
  }
  return 0;
}
