#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35;
int n, m;
int a[MAXN][MAXN];
int part[MAXN][MAXN], partn = 0;
long long ans = 0;
int x[MAXN][2];
int res[MAXN][MAXN];
int c[MAXN];
int u[MAXN];
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    char tmp[35];
    scanf("%s", tmp + 1);
    for (int j = 1; j <= m; j++) {
      if (tmp[j] == '.')
        a[i][j] = 0;
      else if (tmp[j] >= 'a')
        a[i][j] = tmp[j] - 'a' + 1;
      else
        a[i][j] = tmp[j] - 'A' + 26 + 1;
    }
  }
}
void prepare() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] != 0 && !part[i][j]) {
        partn++;
        part[i][j] = part[i][j + 1] = part[i + 1][j] = part[i + 1][j + 1] =
            partn;
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] != 0) {
        int k = a[i][j];
        if (x[k][0] == 0)
          x[k][0] = part[i][j];
        else
          x[k][1] = part[i][j];
      }
  for (int i = 1; i <= 28; i++) {
    if (x[i][0] > x[i][1]) x[i][0] ^= x[i][1] ^= x[i][0] ^= x[i][1];
  }
}
bool chk(int p) {
  bool e[10][10];
  memset(e, 0, sizeof(e));
  for (int i = 1; i <= 28; i++)
    if (x[i][1] <= p) {
      int f = c[x[i][0]], g = c[x[i][1]];
      if (f > g) f ^= g ^= f ^= g;
      if (e[f][g]) return false;
      e[f][g] = true;
    }
  return true;
}
void dfs(int p) {
  if (p > partn) {
    if (ans == 0) {
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
          if (a[i][j] != 0) res[i][j] = c[part[i][j]];
    }
    ans += 5040;
    return;
  }
  for (int i = 0; i <= 6; i++)
    if (u[i] <= 1) {
      c[p] = i;
      if (!chk(p)) continue;
      u[i]++;
      dfs(p + 1);
      u[i]--;
      if (u[i] == 0) return;
    }
}
void work() { dfs(1); }
void print() {
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 0)
        printf(".");
      else
        printf("%d", res[i][j]);
    }
    printf("\n");
  }
}
int main() {
  read();
  prepare();
  work();
  print();
  return 0;
}
