#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[30][31];
char w[30][31];
struct Square {
  int i, j;
};
int k, res;
Square a[14];
int p[14];
int sol[14];
bool used[7][7];
bool check() {
  for (int i = 0; i < 14; i++) {
    w[a[i].i][a[i].j] = p[i];
    w[a[i].i + 1][a[i].j] = p[i];
    w[a[i].i][a[i].j + 1] = p[i];
    w[a[i].i + 1][a[i].j + 1] = p[i];
  }
  memset(used, 0, sizeof used);
  int x, y;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (w[i][j] != '.') {
        if (s[i][j] == s[i][j + 1]) {
          x = w[i][j];
          y = w[i][j + 1];
          if (x > y) swap(x, y);
          if (used[x][y]) return false;
          used[x][y] = true;
          w[i][j + 1] = '.';
        } else {
          x = w[i][j];
          y = w[i + 1][j];
          if (x > y) swap(x, y);
          if (used[x][y]) return false;
          used[x][y] = true;
          w[i + 1][j] = '.';
        }
        w[i][j] = '.';
      }
  return true;
}
void go(int pos, int id) {
  if (pos == 14) {
    if (check()) {
      if (!res) memcpy(sol, p, sizeof p);
      res++;
    }
    return;
  }
  if (p[pos] != -1) {
    go(pos + 1, id);
    return;
  }
  p[pos] = id;
  for (int i = pos + 1; i < 14; i++)
    if (p[i] == -1) {
      p[i] = id;
      go(pos + 1, id + 1);
      p[i] = -1;
    }
  p[pos] = -1;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  memcpy(w, s, sizeof s);
  k = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (w[i][j] != '.') {
        a[k].i = i;
        a[k].j = j;
        k++;
        w[i][j] = w[i + 1][j] = w[i][j + 1] = w[i + 1][j + 1] = '.';
      }
  res = 0;
  memset(p, -1, sizeof p);
  go(0, 0);
  do {
  } while (next_permutation(p, p + 14));
  printf("%d\n", res * 5040);
  for (int i = 0; i < 14; i++) {
    s[a[i].i][a[i].j] = sol[i] + '0';
    s[a[i].i + 1][a[i].j] = sol[i] + '0';
    s[a[i].i][a[i].j + 1] = sol[i] + '0';
    s[a[i].i + 1][a[i].j + 1] = sol[i] + '0';
  }
  for (int i = 0; i < n; i++) puts(s[i]);
  return 0;
}
