#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[33][33];
int b[33][33], cf[33], cs[33], cnt(0);
bool used[7][7];
int ans(0), num[33];
bool flag(0);
int rnum[33];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if (s[i][j] == '.') continue;
      if (!b[i][j])
        b[i][j] = b[i][j + 1] = b[i + 1][j] = b[i + 1][j + 1] = ++cnt;
      int cnum = s[i][j] < 'a' ? s[i][j] - 'A' + 26 : s[i][j] - 'a';
      if (cf[cnum])
        cs[cnum] = b[i][j];
      else
        cf[cnum] = b[i][j];
    }
}
bool *pu(int x, int y) { return &used[min(x, y)][max(x, y)]; }
void dfs(int k, int c) {
  if (k > 14) {
    memset(used, 0, sizeof(used));
    for (int i = 0; i < 28; ++i) {
      if (*pu(num[cf[i]], num[cs[i]])) return;
      *pu(num[cf[i]], num[cs[i]]) = 1;
    }
    ++ans;
    if (flag) return;
    memcpy(rnum, num, sizeof(num));
    flag = 1;
    return;
  }
  if (num[k] >= 0) {
    dfs(k + 1, c);
    return;
  }
  num[k] = c;
  for (int i = k + 1; i <= 14; ++i) {
    if (num[i] >= 0) continue;
    num[i] = c;
    dfs(k + 1, c + 1);
    num[i] = -1;
  }
  num[k] = -1;
}
void work() {
  memset(num, -1, sizeof(num));
  dfs(1, 0);
  printf("%d\n", ans * 5040);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '.')
        printf(".");
      else
        printf("%d", rnum[b[i][j]]);
    printf("\n");
  }
}
int main() {
  init();
  work();
  return 0;
}
