#include <bits/stdc++.h>
using namespace std;
bool nuru(vector<vector<char> > &field, int y, int x) {
  if (field[y][x] == '#' || field[y][x] == 'x') {
    field[y][x] = 'x';
    return false;
  }
  if (y == 1 || y == field.size() - 2 || x == 1 || x == field[0].size() - 2)
    return true;
  field[y][x] = 'x';
  return nuru(field, y + 1, x) || nuru(field, y - 1, x) ||
         nuru(field, y, x + 1) || nuru(field, y, x - 1);
}
int solve(int n, int m) {
  int gy, gx;
  vector<vector<char> > field(m + 4, vector<char>(n + 4));
  for (int i = 0; i < n + 4; i++) {
    field[0][i] = '#';
    field[m + 3][i] = '#';
  }
  for (int i = 0; i < m + 4; i++) {
    field[i][0] = '#';
    field[i][n + 3] = '#';
  }
  for (int i = 1; i < n + 3; i++) {
    field[1][i] = '.';
    field[m + 2][i] = '.';
  }
  for (int i = 1; i < m + 3; i++) {
    field[i][1] = '.';
    field[i][n + 2] = '.';
  }
  for (int i = 2; i < m + 2; i++) {
    for (int j = 2; j < n + 2; j++) {
      char c;
      cin >> c;
      field[i][j] = c;
      if (c == '&') {
        gy = i;
        gx = j;
      }
    }
  }
  int ret = 0;
  while (true) {
    if (nuru(field, gy, gx)) {
      return ret;
    }
    for (int i = 0; i < m + 4; i++) {
      for (int j = 0; j < n + 4; j++) {
        if (field[i][j] == 'x') {
          field[i][j] = '.';
        }
      }
    }
    ret++;
  }
  cout << nuru(field, gy, gx) << endl;
  for (int i = 0; i < m + 4; i++) {
    for (int j = 0; j < n + 4; j++) {
      cout << field[i][j];
    }
    cout << endl;
  }
}
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == m && n == 0) break;
    cout << solve(n, m) << endl;
  }
  return 0;
}
