#include <bits/stdc++.h>
using namespace std;
const int mx[] = {-1, 0, 1, 0}, my[] = {0, -1, 0, 1};
char chip[32][32];
int sqr[32][32];
int n, m;
int dir[32][32];
int val[32];
int ans;
bool used[8][8];
char sol[32][32];
int num[8];
int px[1024], py[1024], pn;
inline bool setval(int y, int x, int v) {
  int p = sqr[y][x];
  if (val[p] < 0) {
    val[p] = v;
    return true;
  } else {
    return val[p] == v;
  }
}
inline int getval(int y, int x) { return val[sqr[y][x]]; }
bool check() {
  memset(used, 0, sizeof(used));
  for (int i = 0; i < pn; i++) {
    int y1 = py[i], x1 = px[i];
    int y2 = y1 + my[dir[y1][x1]], x2 = x1 + mx[dir[y1][x1]];
    int v1 = val[sqr[y1][x1]], v2 = val[sqr[y2][x2]];
    if (used[v1][v2]) return false;
    used[v1][v2] = used[v2][v1] = true;
  }
  return true;
}
void search(int p, int d) {
  if (p == 14) {
    if (check()) {
      if (ans == 0) {
        for (int i = 0; i < n; i++) {
          for (int j = 0; j < m; j++)
            sol[i][j] = (sqr[i][j] >= 0) ? val[sqr[i][j]] + '0' : '.';
          sol[i][m] = 0;
        }
      }
      ans++;
    }
    return;
  }
  for (int i = 0; i < p; i++) {
    if (num[val[i]] >= 2) continue;
    num[val[i]]++;
    val[p] = val[i];
    search(p + 1, d);
    num[val[i]]--;
  }
  if (d <= 6) {
    val[p] = d;
    num[d]++;
    search(p + 1, d + 1);
    num[d]--;
  }
}
void solve() {
  ans = 0;
  memset(val, 255, sizeof(val));
  memset(num, 0, sizeof(num));
  search(0, 0);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", chip[i]);
  }
  memset(dir, 255, sizeof(dir));
  memset(sqr, 255, sizeof(sqr));
  int bn = 0;
  pn = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (chip[i][j] == '.') continue;
      for (int k = 0; k < 4; k++) {
        int y = i + my[k], x = j + mx[k];
        if (y < 0 || x < 0 || y >= n || x >= m) continue;
        if (chip[i][j] == chip[y][x]) {
          dir[i][j] = k;
          if (k >= 2) {
            py[pn] = i;
            px[pn] = j;
            pn++;
          }
          break;
        }
      }
      if (sqr[i][j] < 0 && chip[i][j] != '.') {
        sqr[i][j] = bn;
        sqr[i + 1][j] = bn;
        sqr[i][j + 1] = bn;
        sqr[i + 1][j + 1] = bn;
        bn++;
      }
    }
  solve();
  printf("%d\n", ans * 5040);
  for (int i = 0; i < n; i++) puts(sol[i]);
  return 0;
}
