#include <bits/stdc++.h>
int N, M, i, j, e, Ans, Cnt;
char Map[35][35], res[35][35];
int f[35][35], h[10][10], P[15], g[10], son[15], next[205], ed[205];
bool check(int i) {
  int j, flag = 1;
  for (j = son[i]; j; j = next[j]) {
    if (h[P[i]][P[ed[j]]]) flag = 0;
    ++h[P[i]][P[ed[j]]];
  }
  for (j = son[i]; j; j = next[j]) --h[P[i]][P[ed[j]]];
  return flag;
}
void Addedge(int i, int j) {
  int tmp;
  if (i < j) tmp = i, i = j, j = tmp;
  ed[++e] = j, next[e] = son[i], son[i] = e;
}
void Add(int i) {
  int j;
  for (j = son[i]; j; j = next[j]) h[P[i]][P[ed[j]]] = h[P[ed[j]]][P[i]] = 1;
}
void Del(int i) {
  int j;
  for (j = son[i]; j; j = next[j]) h[P[i]][P[ed[j]]] = h[P[ed[j]]][P[i]] = 0;
}
void prt() {
  int i, j;
  for (i = 0; i < N; ++i)
    for (j = 0; j < M; ++j)
      if (f[i][j])
        res[i][j] = P[f[i][j]] + '0';
      else
        res[i][j] = '.';
}
void dfs(int i) {
  int j;
  if (i > 14) {
    ++Ans;
    if (Ans == 1) prt();
    return;
  }
  for (j = 0; j < 7; ++j)
    if (g[j] == 1) {
      P[i] = j, ++g[j];
      if (check(i)) Add(i), dfs(i + 1), Del(i);
      --g[j];
    }
  for (j = 0; j < 7; ++j)
    if (g[j] == 0) {
      P[i] = j, ++g[j];
      if (check(i)) Add(i), dfs(i + 1), Del(i);
      --g[j];
      break;
    }
}
int main() {
  scanf("%d%d", &N, &M);
  for (i = 0; i < N; ++i) scanf("%s", Map[i]);
  for (i = 0; i < N; ++i)
    for (j = 0; j < M; ++j)
      if (Map[i][j] != '.' && !f[i][j])
        f[i][j] = f[i + 1][j] = f[i][j + 1] = f[i + 1][j + 1] = ++Cnt;
  for (i = 0; i < N; ++i)
    for (j = 0; j < M; ++j)
      if (Map[i][j] != '.') {
        if (i > 0 && Map[i][j] == Map[i - 1][j]) Addedge(f[i][j], f[i - 1][j]);
        if (j > 0 && Map[i][j] == Map[i][j - 1]) Addedge(f[i][j], f[i][j - 1]);
      }
  dfs(1);
  printf("%d\n", 5040ll * Ans);
  for (i = 0; i < N; ++i) printf("%s\n", res[i]);
  return 0;
}
