#include <bits/stdc++.h>
using namespace std;
int n, m;
int omap[102][102];
int map[102][102];
void dfs(int i, int j) {
  const int ci[] = {-1, 0, 1, 0};
  const int cj[] = {0, 1, 0, -1};
  if (i < 0 || i > m + 2 || j < 0 || j > n + 2) return;
  if (map[i][j] == 1) return;
  map[i][j] = 1;
  for (int k = 0; k < sizeof(ci) / sizeof(*ci); ++k) {
    dfs(i + ci[k], j + cj[k]);
  }
  return;
}
void printMap() {
  for (int i = 0; i < m + 2; ++i) {
    for (int j = 0; j < n + 2; ++j) {
      cout << map[i][j];
    }
    cout << endl;
  }
  cout << endl;
}
int main() {
  while (true) {
    int si, sj;
    int ans = 1000;
    int tans = 0;
    cin >> n >> m;
    if (m == 0 && n == 0) break;
    for (int i = 0; i < 102; ++i) {
      for (int j = 0; j < 102; ++j) {
        omap[i][j] = map[i][j] = 0;
      }
    }
    for (int i = 1; i < m + 1; ++i) {
      string s;
      cin >> s;
      for (int j = 1; j < n + 1; ++j) {
        if (s[j - 1] == '.') {
          omap[i][j] = map[i][j] = 0;
        } else if (s[j - 1] == '&') {
          si = i;
          sj = j;
          omap[i][j] = map[i][j] = 0;
        } else if (s[j - 1] == '#') {
          omap[i][j] = map[i][j] = 1;
        }
      }
    }
    for (int i = si - 1; i >= 0; --i) {
      if (map[i][sj] == 0) {
        dfs(i, sj);
        ++tans;
      }
    }
    for (int i = 0; i < 102; ++i)
      for (int j = 0; j < 102; ++j) map[i][j] = omap[i][j];
    ans = min(ans, tans);
    for (int i = si + 1; i <= m + 1; ++i) {
      if (map[i][sj] == 0) {
        dfs(i, sj);
        ++tans;
      }
    }
    for (int i = 0; i < 102; ++i)
      for (int j = 0; j < 102; ++j) map[i][j] = omap[i][j];
    ans = min(ans, tans);
    for (int j = sj - 1; j >= 0; --j) {
      if (map[si][j] == 0) {
        dfs(si, j);
        ++tans;
      }
    }
    for (int i = 0; i < 102; ++i)
      for (int j = 0; j < 102; ++j) map[i][j] = omap[i][j];
    ans = min(ans, tans);
    for (int j = sj + 1; j <= n + 1; ++j) {
      if (map[si][j] == 0) {
        dfs(si, j);
        ++tans;
      }
    }
    for (int i = 0; i < 102; ++i)
      for (int j = 0; j < 102; ++j) map[i][j] = omap[i][j];
    ans = min(ans, tans);
    cout << ans - 1 << endl;
  }
  return 0;
}
