#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long INF64 = 1e18;
const long double EPS = 1e-7;
mt19937 myrand(time(NULL));
const int N = 31;
const int AL = 7;
int n, m;
char a[N][N];
bool read() {
  if (scanf("%d%d\n", &n, &m) != 2) return 0;
  for (int i = 0; i < (n); i++) scanf("%s\n", a[i]);
  return 1;
}
int b[N][N];
char g[N][N];
char used[AL][AL];
int cur[N], res[N];
long long ans;
int cnt;
void brute(int v, int clr) {
  if (v == cnt) {
    if (ans == 0)
      for (int i = 0; i < (N); i++) res[i] = cur[i];
    ans++;
    return;
  }
  for (int i = 0; i < (min(7, clr + 1)); i++) {
    cur[v] = i;
    bool fl = 1;
    for (int j = 0; j < (v + 1); j++)
      if (g[v][j] && used[cur[j]][i]) fl = 0;
    if (fl) {
      for (int j = 0; j < (v + 1); j++)
        if (g[v][j]) {
          if (!used[cur[j]][i])
            used[cur[j]][i] = used[i][cur[j]] = 1;
          else
            fl = 0;
        }
      if (fl) brute(v + 1, max(clr, i + 1));
      for (int j = 0; j < (v + 1); j++)
        if (g[v][j]) used[cur[j]][i] = used[i][cur[j]] = 0;
    }
  }
}
void solve() {
  cnt = 0;
  memset(b, 255, sizeof(b));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++)
      if (a[i][j] != '.' && b[i][j] == -1) {
        b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = cnt;
        cnt++;
      }
  ans = 0;
  memset(used, 0, sizeof(used));
  memset(g, 0, sizeof(g));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      if (a[i][j] == '.') continue;
      if (i > 0 && a[i - 1][j] == a[i][j])
        g[b[i][j]][b[i - 1][j]] = g[b[i - 1][j]][b[i][j]] = 1;
      if (j > 0 && a[i][j - 1] == a[i][j])
        g[b[i][j]][b[i][j - 1]] = g[b[i][j - 1]][b[i][j]] = 1;
    }
  ans = 0;
  memset(used, 0, sizeof(used));
  memset(cur, 255, sizeof(cur));
  memset(res, 255, sizeof(res));
  brute(0, 0);
  printf("%lld\n", ans * 5040);
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++)
      printf("%c", b[i][j] == -1 ? '.' : '0' + res[b[i][j]]);
    printf("\n");
  }
}
int main() {
  while (read()) solve();
  return 0;
}
