#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
int w, h;
char field[100][100];
char iniField[100][100];
char ansField[100][100];
pair<int, int> state[100];
int used[100];
int mapto[100][100];
bool Set(int x, int y, int v) {
  field[y][x] = v + '0';
  char c = iniField[y][x];
  int index = islower(c) ? c - 'a' : c - 'A' + 26;
  if (state[index].first == -1) {
    assert(state[index].second == -1);
    state[index].first = v;
  } else {
    assert(state[index].second == -1);
    state[index].second = v;
    int m = mapto[state[index].first][v];
    used[m]++;
    if (used[m] >= 2) {
      return false;
    }
  }
  return true;
}
void Revert(int x, int y) {
  field[y][x] = iniField[y][x];
  char c = iniField[y][x];
  int index = islower(c) ? c - 'a' : c - 'A' + 26;
  if (state[index].second != -1) {
    assert(state[index].first != -1);
    int m = mapto[state[index].first][state[index].second];
    used[m]--;
    state[index].second = -1;
  } else {
    assert(state[index].first != -1);
    state[index].first = -1;
  }
}
int calc(int x, int y, bool first) {
  if (y == h) {
    if (ansField[0][0] == 0) {
      memcpy(ansField, field, sizeof(field));
    }
    return 1;
  }
  if (x == w) {
    return calc(0, y + 1, first);
  }
  if (field[y][x] == '.' || isdigit(field[y][x])) {
    return calc(x + 1, y, first);
  }
  assert(field[y][x + 1] != '.');
  assert(field[y + 1][x] != '.');
  assert(field[y + 1][x + 1] != '.');
  int ret = 0;
  for (int i = 0; i < (int)(7); i++) {
    bool ok = true;
    ok &= Set(x, y, i);
    ok &= Set(x + 1, y, i);
    ok &= Set(x, y + 1, i);
    ok &= Set(x + 1, y + 1, i);
    if (ok) {
      ret += calc(x + 1, y, false);
    }
    Revert(x, y);
    Revert(x + 1, y);
    Revert(x, y + 1);
    Revert(x + 1, y + 1);
    if (first) {
      break;
    }
  }
  return ret;
}
int main() {
  memset((state), -1, sizeof(state));
  memset((ansField), 0, sizeof(ansField));
  scanf("%d %d", &h, &w);
  for (int y = 0; y < (int)(h); y++) {
    scanf("%s", field[y]);
  }
  int cnt = 0;
  for (int i = (0); i <= (int)(6); i++) {
    for (int j = (i); j <= (int)(6); j++) {
      mapto[i][j] = cnt;
      mapto[j][i] = cnt++;
    }
  }
  memcpy(iniField, field, sizeof(field));
  int ans = calc(0, 0, true) * 7;
  printf("%d\n", ans);
  for (int y = 0; y < (int)(h); y++) {
    printf("%s\n", ansField[y]);
  }
}
