#include <bits/stdc++.h>
using namespace std;
int top, n, m;
bool flag[70], pr;
int ch[150], a[7], f[35][35], x[15], y[15];
int pri[35][35];
char s[35][35];
long long ans;
bool check() {
  for (int i = 'A'; i <= 'Z'; i++) ch[i] = ch[i - 'A' + 'a'] = -1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] != '.')
        if (ch[s[i][j]] == -1)
          ch[s[i][j]] = f[i][j];
        else
          ch[s[i][j]] = ch[s[i][j]] * 10 + f[i][j];
  for (int i = 0; i <= 6; i++)
    for (int j = 0; j <= i; j++) flag[j * 10 + i] = true;
  for (int i = 'A'; i <= 'Z'; i++)
    if (ch[i] != -1) {
      if (ch[i] / 10 > ch[i] % 10) ch[i] = ch[i] / 10 + ch[i] % 10 * 10;
      if (!flag[ch[i]]) return false;
      flag[ch[i]] = false;
    }
  for (int i = 'a'; i <= 'z'; i++)
    if (ch[i] != -1) {
      if (ch[i] / 10 > ch[i] % 10) ch[i] = ch[i] / 10 + ch[i] % 10 * 10;
      if (!flag[ch[i]]) return false;
      flag[ch[i]] = false;
    }
  return true;
}
void dfs(int d) {
  if (d == 15) {
    if (check()) {
      ans += 5040;
      if (!pr) {
        for (int i = 1; i <= n; i++)
          for (int j = 1; j <= m; j++) pri[i][j] = f[i][j];
        pr = true;
      }
    }
    return;
  }
  int q = top;
  for (int i = 0; i <= q; i++)
    if (a[i] < 2) {
      if (i == top && top < 6) top++;
      f[x[d]][y[d]] = i;
      f[x[d] + 1][y[d]] = i;
      f[x[d]][y[d] + 1] = i;
      f[x[d] + 1][y[d] + 1] = i;
      a[i]++;
      dfs(d + 1);
      a[i]--;
      f[x[d]][y[d]] = 0;
      f[x[d] + 1][y[d]] = 0;
      f[x[d]][y[d] + 1] = 0;
      f[x[d] + 1][y[d] + 1] = 0;
      top = q;
    }
}
int main() {
  scanf("%d%d", &n, &m);
  memset(f, -1, sizeof(f));
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= m; j++)
      if (f[i][j] == -1 && s[i][j] != '.') {
        x[++tot] = i;
        y[tot] = j;
        f[i][j] = 0;
        f[i][j + 1] = 0;
        f[i + 1][j] = 0;
        f[i + 1][j + 1] = 0;
      }
  }
  dfs(1);
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (pri[i][j] == -1)
        printf(".");
      else
        printf("%d", pri[i][j]);
    printf("\n");
  }
  return 0;
}
