#include <bits/stdc++.h>
using namespace std;
const int maxn = 35;
const int each = 5040;
char st[maxn][maxn];
char ans[maxn][maxn];
int ord[maxn][maxn];
int ax[maxn], ay[maxn];
int vis[maxn];
int n, m, os, ret;
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", st[i] + 1);
}
int dit(char ch) {
  if (ch >= 'a') return ch - 'a';
  return ch - 'A' + 26;
}
bool f[maxn][maxn];
bool check() {
  memset(f, 0, sizeof(f));
  for (int i = 0; i < 28; i++) {
    int x = vis[ax[i]], y = vis[ay[i]];
    if (f[x][y]) return 0;
    f[x][y] = f[y][x] = true;
  }
  return 1;
}
void dfs(int x, int y) {
  if (x > 14) {
    if (!check()) return;
    ret++;
    if (ret == 1) {
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
          ans[i][j] = ord[i][j] ? vis[ord[i][j]] + '0' : '.';
    }
    return;
  }
  if (vis[x] != -1) dfs(x + 1, y);
  if (vis[x] == -1) {
    vis[x] = y;
    for (int i = x; i <= 14; i++)
      if (vis[i] == -1) {
        vis[i] = y;
        dfs(x + 1, y + 1);
        vis[i] = -1;
      }
    vis[x] = -1;
  }
}
void work() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (st[i][j] != '.') {
        int cur = dit(st[i][j]);
        if (!ord[i][j]) {
          ord[i][j] = ord[i + 1][j] = ord[i][j + 1] = ord[i + 1][j + 1] = ++os;
        }
        if (!ax[cur])
          ax[cur] = ord[i][j];
        else
          ay[cur] = ord[i][j];
      }
  memset(vis, -1, sizeof(vis));
  dfs(1, 0);
  ret *= each;
}
void print() {
  printf("%d\n", ret);
  for (int i = 1; i <= n; i++) printf("%s\n", ans[i] + 1);
}
int main() {
  init();
  work();
  print();
  return 0;
}
