#include <bits/stdc++.h>
using namespace std;
string s[100];
char c[] = {'#', '.'};
int w, h, p, sum;
void dfs(int i, int j) {
  if (i == h || j == w || i < 0 || j < 0) return;
  if (s[i][j] == c[p]) return;
  s[i][j] = c[p];
  dfs(i + 1, j);
  dfs(i - 1, j);
  dfs(i, j + 1);
  dfs(i, j - 1);
  if (i == h - 1 || j == w - 1 || i * j == 0) sum = 1;
}
int main() {
  int cc = 0;
  while (cin >> w >> h, w) {
    sum = 0;
    for (int i = 0; i < h; i++) cin >> s[i];
    int su = 0;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) {
        if (s[i][j] == '&') {
          p = 0;
          dfs(i, j);
          if (sum) goto L;
          su++;
          p = 1;
          dfs(i, j);
          if (sum) goto L;
        }
      }
  L:
    cout << su << endl;
  }
}
