#include <bits/stdc++.h>
int a, b, c, d, e, f, g[35][35], h[35], i, j;
char w[35][35];
int v[10][10];
int vv[10];
int an;
int T[35][35];
int qx, qy, zx, zy;
void Get(int x, int y) {
  int ii, jj, kk;
  if (x > zx) {
    an++;
    for (ii = 1; ii <= a; ii++)
      for (jj = 1; jj <= b; jj++) {
        if (w[ii][jj] == '.')
          T[ii][jj] = -5;
        else
          T[ii][jj] = h[g[ii][jj]];
      }
    return;
  }
  if (y > zy) {
    Get(x + 1, 1);
    return;
  }
  if (w[x][y] == '.') {
    Get(x, y + 1);
    return;
  }
  if (w[x][y - 1] == w[x][y] || w[x - 1][y] == w[x][y]) {
    Get(x, y + 1);
    return;
  }
  if (w[x][y + 1] == w[x][y]) {
    ii = h[g[x][y]];
    jj = h[g[x][y + 1]];
    if (v[ii][jj] == 0) {
      v[ii][jj] = 1;
      v[jj][ii] = 1;
      Get(x, y + 1);
      v[ii][jj] = 0;
      v[jj][ii] = 0;
    }
    return;
  }
  if (w[x + 1][y] == w[x][y]) {
    ii = h[g[x][y]];
    jj = h[g[x + 1][y]];
    if (v[ii][jj] == 0) {
      v[ii][jj] = 1;
      v[jj][ii] = 1;
      Get(x, y + 1);
      v[ii][jj] = 0;
      v[jj][ii] = 0;
    }
  }
}
void soso(int x) {
  int ii, jj, kk;
  if (x == d + 1) {
    Get(qx, qy);
    return;
  }
  for (ii = 0; ii <= 6; ii++) {
    if (vv[ii] < 2) {
      vv[ii]++;
      h[x] = ii;
      soso(x + 1);
      vv[ii]--;
    }
    if (vv[ii] == 0) break;
  }
}
int main() {
  scanf("%d%d", &a, &b);
  for (i = 1; i <= a; i++) scanf("%s", w[i] + 1);
  qx = 1 << 30;
  qy = 1 << 30;
  zx = -qx;
  zy = -qy;
  for (i = 1; i <= a; i++)
    for (j = 1; j <= b; j++)
      if (w[i][j] != '.') {
        if (i < qx) qx = i;
        if (i > zx) zx = i;
        if (j < qy) qy = j;
        if (j > zy) zy = j;
      }
  for (i = 1; i <= a; i++)
    for (j = 1; j <= b; j++)
      if (w[i][j] != '.' && g[i][j] == 0) {
        g[i][j] = ++d;
        g[i + 1][j] = d;
        g[i][j + 1] = d;
        g[i + 1][j + 1] = d;
      }
  soso(1);
  printf("%d\n", an * 1 * 2 * 3 * 4 * 5 * 6 * 7);
  for (i = 1; i <= a; i++, printf("\n"))
    for (j = 1; j <= b; j++)
      if (T[i][j] == -5)
        printf("%c", '.');
      else
        printf("%d", T[i][j]);
  return 0;
}
