#include <bits/stdc++.h>
using namespace std;
struct Node {
  int i, j;
  int w;
  int v;
  bool vis;
};
class GreaterPNode {
 public:
  bool operator()(const Node *a, const Node *b) const { return a->w > b->w; }
};
int n, m;
Node map[102][102];
bool inRange(int t, int Min, int Max) { return Min <= t && t < Max; }
int dijkstra(int i, int j, int gi, int gj) {
  const int ci[] = {-1, 0, 1, 0};
  const int cj[] = {0, 1, 0, -1};
  Node *p = &map[i][j];
  priority_queue<Node *, vector<Node *>, GreaterPNode> pq;
  p->w = 0;
  pq.push(p);
  while (!pq.empty()) {
    p = pq.top();
    pq.pop();
    p->vis = false;
    for (int k = 0; k < 4; ++k) {
      int ti = p->i + ci[k], tj = p->j + cj[k];
      if (inRange(ti, 1, m + 1) && inRange(tj, 1, n + 1)) {
        int cost = 0;
        Node *q = &map[ti][tj];
        if (p->v == 1 && q->v == 2) {
          cost = 1;
        }
        if (!q->vis && q->w > p->w + cost) {
          q->w = p->w + cost;
          pq.push(q);
        }
      }
    }
  }
  return -1;
}
void ResetMap(bool bAll) {
  for (int i = (0); i < (102); ++i)
    for (int j = (0); j < (102); ++j) {
      map[i][j].i = i;
      map[i][j].j = j;
      if (bAll) map[i][j].v = 2;
      map[i][j].w = 1 << 30;
      map[i][j].vis = false;
    }
}
void PrintMap() {
  for (int i = (1); i < (m + 1); ++i) {
    for (int j = (1); j < (n + 1); ++j) {
      cout << setw(3) << map[i][j].w;
    }
    cout << endl;
  }
  cout << endl;
}
int main() {
  while (true) {
    int gi, gj;
    int ans = 1 << 30;
    cin >> n >> m;
    if (m == 0 && n == 0) break;
    ResetMap(true);
    for (int i = (1); i < (m + 1); ++i) {
      string s;
      cin >> s;
      for (int j = (1); j < (n + 1); ++j) {
        if (s[j - 1] == '&') {
          gi = i;
          gj = j;
        } else if (s[j - 1] == '#') {
          map[i][j].v = 1;
        }
      }
    }
    for (int i = (1); i < (m + 1); ++i) {
      dijkstra(i, 1, gi, gj);
      ans = min(ans, map[gi][gj].w);
      ResetMap(false);
    }
    for (int i = (1); i < (m + 1); ++i) {
      dijkstra(i, n, gi, gj);
      ans = min(ans, map[gi][gj].w);
      ResetMap(false);
    }
    for (int j = (1); j < (n + 1); ++j) {
      dijkstra(1, j, gi, gj);
      ans = min(ans, map[gi][gj].w);
      ResetMap(false);
    }
    for (int j = (1); j < (n + 1); ++j) {
      dijkstra(m, j, gi, gj);
      ans = min(ans, map[gi][gj].w);
      ResetMap(false);
    }
    cout << ans << endl;
  }
  return 0;
}
