#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int h, w;
char mapData[100][100];
bool visited[100][100];
int gx, gy;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int height[100][100];
int p;
void dfs(int y, int x) {
  for (int i = 0; i < 4; i++) {
    int ty = y + dy[i];
    int tx = x + dx[i];
    if (ty < 0 || ty >= h) continue;
    if (tx < 0 || tx >= w) continue;
    if (mapData[ty][tx] == '#') continue;
    if (height[ty][tx] == p && visited[ty][tx]) continue;
    if (height[ty][tx] < p) return;
    visited[ty][tx] = true;
    height[y][x] = p;
    dfs(ty, tx);
  }
}
int solve() {
  fill(height[0], height[100], INF);
  int cnt;
  for (int j = 0; j < w; j++) {
    cnt = 0;
    for (int i = 0; i < h; i++) {
      if (mapData[i][j] == '#') {
        height[i][j] = -1;
        cnt++;
      }
      height[i][j] = min(height[i][j], cnt);
    }
  }
  for (int i = 0; i < h; i++) {
    cnt = 0;
    for (int j = w - 1; j >= 0; j--) {
      if (mapData[i][j] == '#') {
        height[i][j] = -1;
        cnt++;
        height[i][j] = min(height[i][j], cnt);
      }
    }
  }
  for (int j = 0; j < w; j++) {
    cnt = 0;
    for (int i = h - 1; i >= 0; i--) {
      if (mapData[i][j] == '#') {
        height[i][j] = -1;
        cnt++;
      }
      height[i][j] = min(height[i][j], cnt);
    }
  }
  for (int i = 0; i < h; i++) {
    cnt = 0;
    for (int j = 0; j < w; j++) {
      if (mapData[i][j] == '#') {
        height[i][j] = -1;
        cnt++;
      }
      height[i][j] = min(height[i][j], cnt);
    }
  }
  fill(visited[0], visited[100], false);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (mapData[i][j] == '#' || visited[i][j]) continue;
      p = height[i][j];
      dfs(i, j);
    }
  }
  return height[gy][gx];
}
int main() {
  while (cin >> w >> h && (h || w)) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> mapData[i][j];
        if (mapData[i][j] == '&') {
          mapData[i][j] = '.';
          gy = i;
          gx = j;
        }
      }
    }
    cout << solve() << endl;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cout << setw(2) << height[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
