#include <bits/stdc++.h>
int n, m, ans = 0, re[15], a[29][2], temp[31][31], last[31][31];
char s[31][31];
void swap(int &a, int &b) {
  int temp = a;
  a = b;
  b = temp;
}
void work(int d, int w) {
  int i;
  if (d > 14) {
    bool p[29][29];
    memset(p, false, sizeof(p));
    for (i = 1; i <= 28; i++) {
      int t1 = re[a[i][0]], t2 = re[a[i][1]];
      if (t1 > t2) swap(t1, t2);
      if (p[t1][t2]) return;
      p[t1][t2] = true;
    }
    ans++;
    if (ans == 1)
      for (i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) last[i][j] = re[temp[i][j]];
    return;
  }
  if (re[d] != 0)
    work(d + 1, w);
  else {
    re[d] = w;
    for (i = d + 1; i <= 14; i++)
      if (re[i] == 0) {
        re[i] = w;
        work(d + 1, w + 1);
        re[i] = 0;
      }
    re[d] = 0;
  }
}
int main() {
  memset(a, 0, sizeof(a));
  memset(temp, 0, sizeof(temp));
  memset(re, 0, sizeof(re));
  int i, j, sum = 0, d;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (j = 1; j <= m; j++)
      if (s[i][j] != '.') {
        if (temp[i][j] == 0) {
          sum++;
          temp[i][j] = temp[i][j + 1] = temp[i + 1][j] = temp[i + 1][j + 1] =
              sum;
        }
        if (int(s[i][j]) > 96)
          d = int(s[i][j]) - 96;
        else
          d = int(s[i][j]) - 38;
        if (a[d][0] == 0)
          a[d][0] = temp[i][j];
        else
          a[d][1] = temp[i][j];
      }
  }
  work(1, 1);
  printf("%d\n", ans * 5040);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++)
      if (s[i][j] == '.')
        printf(".");
      else
        printf("%d", last[i][j] - 1);
    printf("\n");
  }
  return (0);
}
