#include <bits/stdc++.h>
using namespace std;
string s[100];
char c[] = {'#', '.'};
int a, b, p1, p2, dx[] = {1, -1, 0, 0}, dy[] = {0, 0 - 1, 1};
int dfs(int y, int x) {
  int sum = 0;
  s[y][x] = c[p1];
  if (y == 0 || x == 0 || y == a - 1 || x == b - 1) return 1;
  for (int i = 0; i < 4; i++)
    if (x + dx[i] >= 0 && dx[i] + x < b && y + dy[i] >= 0 && dy[i] + y < a)
      if (s[y + dy[i]][x + dx[i]] == c[p2]) sum = dfs(y + dy[i], x + dx[i]);
  return sum;
}
int main() {
  while (cin >> b >> a, a) {
    for (int i = 0; i < a; i++) cin >> s[i];
    int su = 0;
    for (int i = 0; i < a; i++)
      for (int j = 0; j < b; j++) {
        if (s[i][j] == '&') {
          p1 = 0;
          p2 = 1;
          if (dfs(i, j)) goto L;
          p1 = 1;
          p2 = 0;
          su++;
          if (dfs(i, j)) goto L;
        }
      }
  L:
    cout << su << endl;
  }
}
