#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int W, H, my[] = {0, 0, 1, -1}, mx[] = {1, -1, 0, 0};
vector<vector<char> > v;
int solve() {
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 greater<pair<int, pair<int, int> > > >
      open;
  open.push(pair<int, pair<int, int> >(0, pair<int, int>(H - 1, 0)));
  open.push(pair<int, pair<int, int> >(0, pair<int, int>(H - 1, 0)));
  open.push(pair<int, pair<int, int> >(0, pair<int, int>(0, W - 1)));
  open.push(pair<int, pair<int, int> >(0, pair<int, int>(0, W - 1)));
  for (int i = (int)(1); i < (int)(H); ++i)
    open.push(pair<int, pair<int, int> >(0, pair<int, int>(i, 0)));
  for (int i = (int)(1); i < (int)(W); ++i)
    open.push(pair<int, pair<int, int> >(0, pair<int, int>(0, i)));
  vector<vector<int> > closed(H, vector<int>(W, INF));
  while (!open.empty()) {
    pair<int, pair<int, int> > tmp = open.top();
    open.pop();
    int y = tmp.second.first, x = tmp.second.second, cnt = tmp.first;
    if (closed[y][x] <= cnt) continue;
    closed[y][x] = cnt;
    for (int i = 0; i < (int)(4); ++i) {
      int ny = y + my[i], nx = x + mx[i];
      if (ny >= 0 && nx >= 0 && ny < H && nx < W)
        open.push(pair<int, pair<int, int> >(
            (v[y][x] == '#' && v[ny][nx] != '#' ? cnt + 1 : cnt),
            pair<int, int>(ny, nx)));
    }
  }
  pair<int, int> tar;
  for (int i = 0; i < (int)(H); ++i)
    for (int j = 0; j < (int)(W); ++j)
      if (v[i][j] == '&') tar = pair<int, int>(i, j);
  return closed[tar.first][tar.second];
}
int main() {
  while (cin >> W >> H && W) {
    v = vector<vector<char> >(H, vector<char>(W));
    for (int i = 0; i < (int)(H); ++i)
      for (int j = 0; j < (int)(W); ++j) cin >> v[i][j];
    cout << solve() << endl;
  }
  return 0;
}
