#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, i, j, k, c, f1, f2, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
  char d[101][101], g[2] = {'.', '#'};
  while (cin >> x >> y) {
    if (x == 0) break;
    for (i = 0; i < y; i++) cin >> d[i];
    c = 0;
    while (true) {
      f1 = 0;
      f2 = 0;
      while (f1 + f2 == 0) {
        f1 = 1;
        for (i = 0; i < y; i++)
          for (j = 0; j < x; j++) {
            if (d[i][j] == '&') {
              for (k = 0; k < 4; k++) {
                if (d[i + dy[k]][j + dx[k]] == g[c % 2]) {
                  f1 = 0;
                  d[i + dy[k]][j + dx[k]] = '&';
                  if (i + dy[k] == 0 || i + dy[k] == y - 1 || j + dx[k] == 0 ||
                      j + dx[k] == x - 1)
                    f2 = 1;
                }
              }
            }
          }
      }
      if (f2 == 1) break;
      c++;
    }
    cout << (c + 1) / 2 << endl;
  }
  return 0;
}
