#include <bits/stdc++.h>
using namespace std;
int x, y;
char field[100][100];
bool flag;
void DFS(int a, int b) {
  if (field[b][a] == '&') {
    flag = true;
  } else
    field[b][a] = '-';
  if (0 <= b + 1 && b + 1 < y && 0 <= a && a < x &&
      (field[b + 1][a] == '.' || field[b + 1][a] == '&'))
    DFS(a, b + 1);
  if (0 <= b - 1 && b - 1 < y && 0 <= a && a < x &&
      (field[b - 1][a] == '.' || field[b - 1][a] == '&'))
    DFS(a, b - 1);
  if (0 <= b && b < y && 0 <= a + 1 && a + 1 < x &&
      (field[b][a + 1] == '.' || field[b][a + 1] == '&'))
    DFS(a + 1, b);
  if (0 <= b && b < y && 0 <= a - 1 && a - 1 < x &&
      (field[b][a - 1] == '.' || field[b][a - 1] == '&'))
    DFS(a - 1, b);
}
void hey(int a, int b) {
  field[b][a] = '-';
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      if ((0 <= a + j && b + i < y) && (0 <= a + j && a + j < x) &&
          field[b + i][a + j] == '#')
        hey(a + j, b + i);
    }
  }
}
int main() {
  while (cin >> x >> y) {
    if (!x && !y) break;
    for (int i = 0; i < y; i++) {
      for (int j = 0; j < x; j++) {
        cin >> field[i][j];
      }
    }
    for (int i = 0; i < x; i++) {
      if (field[0][i] == '.') field[0][i] = '-';
      if (field[y - 1][i] == '.') field[y - 1][i] = '-';
    }
    for (int i = 0; i < y; i++) {
      if (field[i][0] == '.') field[i][0] = '-';
      if (field[i][x - 1] == '.') field[i][x - 1] = '-';
    }
    int count = 0;
    flag = false;
    for (int i = 0; i < y; i++) {
      for (int j = 0; j < x; j++) {
        if (field[i][j] == '-') DFS(j, i);
      }
    }
    while (!flag) {
      int a, b;
      for (int i = 0; i < y; i++) {
        for (int j = 0; j < x; j++) {
          if (field[i][j] == '#') {
            a = j;
            b = i;
            goto next;
          }
        }
      }
    next:;
      hey(a, b);
      count++;
      flag = false;
      for (int i = 0; i < y; i++) {
        for (int j = 0; j < x; j++) {
          if (field[i][j] == '-') DFS(j, i);
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
