#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}, w, h, t, d[101][101];
string s[101];
void dfs(int a, int b, char p) {
  d[a][b] = t;
  for (int i = 0; i < 4; i++) {
    int y = a + dy[i], x = b + dx[i];
    if (y >= 0 && x >= 0 && y < h && x < w)
      if (d[y][x] == 1e9 && s[y][x] == p) dfs(y, x, p);
  }
}
int main() {
  while (cin >> w >> h, w) {
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) d[i][j] = 1e9;
    for (int i = 0; i < h; i++) cin >> s[i];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        if (s[i][j] == '&') {
          s[i][j] = '.';
          t = 0;
          dfs(i, j, s[i][j]);
        }
    for (int o = 0; o < h * w; o++)
      for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
          if (d[i][j] != 1e9)
            for (int k = 0; k < 4; k++) {
              int y = i + dy[k], x = j + dx[k];
              if (y < 0 || x < 0 || y >= h || x >= w) continue;
              if (s[i][j] == s[y][x]) continue;
              if (s[i][j] == '.')
                t = d[i][j] + 1;
              else
                t = d[i][j];
              if (d[y][x] > t) dfs(y, x, s[i][j]);
            }
    int ans = 1e9;
    for (int i = 0; i < h; i++) ans = min(ans, min(d[i][0], d[i][w - 1]));
    for (int i = 0; i < w; i++) ans = min(ans, min(d[0][i], d[h - 1][i]));
    cout << ans << endl;
  }
}
