#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:32000000")
int n, m;
int pole[40][40];
int sq[40][40];
int k;
int domino[30][2];
int p;
int ans = 0;
int usedCol[40];
int colBlock[40];
int goodCol[40];
int new_sq[40][40];
int new_k;
void rec(int numBlock) {
  if (numBlock > k) {
    bool onePair[7][7];
    for (int i = 0; i < 7; i++)
      for (int j = 0; j < 7; j++) onePair[i][j] = false;
    int j = 0;
    for (j = 0; j < p; j++) {
      int part1 = colBlock[domino[j][0]];
      int part2 = colBlock[domino[j][1]];
      if (part1 > part2) swap(part1, part2);
      if (!onePair[part1][part2])
        onePair[part1][part2] = true;
      else
        break;
    }
    if (j != p) return;
    ans++;
    if (ans == 1) {
      for (int i = 1; i <= k; i++) goodCol[i] = colBlock[i];
    }
  }
  for (int i = 0; i < 7; i++) {
    if (usedCol[i] < 2) {
      colBlock[numBlock] = i;
      usedCol[i]++;
      rec(numBlock + 1);
      colBlock[numBlock] = 0;
      usedCol[i]--;
    }
    if (usedCol[i] == 0) break;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char ch = getchar();
      while (ch == 32 || ch == '\n') ch = getchar();
      pole[i][j] = ch;
      if (ch != '.' && sq[i][j] == 0) {
        k++;
        sq[i][j] = sq[i + 1][j] = sq[i][j + 1] = sq[i + 1][j + 1] = k;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (pole[i][j] != '.' && pole[i][j] == pole[i + 1][j]) {
        domino[p][0] = sq[i][j];
        domino[p][1] = sq[i + 1][j];
        p++;
      } else if (pole[i][j] != '.' && pole[i][j] == pole[i][j + 1]) {
        domino[p][0] = sq[i][j];
        domino[p][1] = sq[i][j + 1];
        p++;
      }
    }
  }
  rec(1);
  ans = ans * 5040;
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (pole[i][j] == '.') {
        new_sq[i][j] = pole[i][j];
        continue;
      } else if (!new_sq[i][j]) {
        new_k++;
        new_sq[i][j] = new_sq[i + 1][j] = new_sq[i][j + 1] =
            new_sq[i + 1][j + 1] = goodCol[new_k] + '0';
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) putchar(new_sq[i][j]);
    printf("\n");
  }
  return 0;
}
