#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int dir[][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
char M[105][105];
int v[105][105];
int n, m;
bool dfs(int cr, int cc, int color, char target) {
  v[cr][cc] = color;
  if (cr == 0 || cr == m + 1 || cc == 0 || cc == n + 1) {
    return true;
  }
  for (int k = 0; k < (4); k++) {
    int nr = cr + dir[k][0], nc = cc + dir[k][1];
    if ((M[nr][nc] == target && v[nr][nc] == INF) || v[nr][nc] < color) {
      return dfs(nr, nc, color, target);
    }
  }
  return false;
}
void init_map() {
  for (int i = 0; i < (m + 2); i++) {
    for (int j = 0; j < (n + 2); j++) {
      M[i][j] = '.';
      v[i][j] = INF;
    }
  }
}
int main() {
  while (cin >> n >> m && n && m) {
    int sr, sc;
    init_map();
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        cin >> M[i][j];
        if (M[i][j] == '&') {
          sr = i, sc = j;
          M[i][j] = '.';
        }
      }
    }
    int res = 0;
    while (1) {
      if (dfs(sr, sc, res, '.')) {
        break;
      }
      res++;
      if (dfs(sr, sc, res, '#')) {
        break;
      }
      res++;
    }
    cout << res / 2 << endl;
  }
  return 0;
}
