#include <bits/stdc++.h>
using namespace std;
const int N = 111;
const int INF = 1e9 + 19;
int n, m;
char s[N][N];
int color[N][N];
int use[N];
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
}
void rec(int x, int y);
void callNext(int x, int y) {
  y++;
  if (y == m) {
    y = 0;
    x++;
  }
  rec(x, y);
}
long long answer;
set<pair<int, int> > q;
void add(int x1, int y1, int x2, int y2) {
  int v = color[x1][y1];
  int u = color[x2][y2];
  assert(0 <= v && v <= 6);
  assert(0 <= u && u <= 6);
  if (v > u) swap(v, u);
  q.insert(make_pair(v, u));
}
int cc = 0;
char ser[N][N];
int t[N];
int tmr;
vector<pair<int, int> > p1;
vector<pair<int, int> > p2;
void rec(int x, int y) {
  tmr++;
  for (int i = 0; i < (int)p1.size(); i++) {
    int v = color[p1[i].first][p1[i].second];
    int u = color[p2[i].first][p2[i].second];
    if (v != -1 && u != -1) {
      if (v > u) swap(v, u);
      int id = v * 7 + u;
      if (t[id] == tmr) return;
      t[id] = tmr;
    }
  }
  if (x == n && y == 0) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (s[i][j] == '.')
          ser[i][j] = '.';
        else
          ser[i][j] = '0' + color[i][j];
    answer++;
    return;
  }
  if (s[x][y] == '.') {
    callNext(x, y);
    return;
  }
  if (color[x][y] != -1) {
    callNext(x, y);
    return;
  }
  if (color[x][y] == -1) {
    for (int i = 0; i < 7; i++) {
      if (use[i] <= 1) {
        use[i]++;
        for (int dx = 0; dx < 2; dx++)
          for (int dy = 0; dy < 2; dy++) color[x + dx][y + dy] = i;
        callNext(x, y);
        use[i]--;
      }
      if (use[i] == 0) break;
    }
    for (int dx = 0; dx < 2; dx++)
      for (int dy = 0; dy < 2; dy++) color[x + dx][y + dy] = -1;
  }
}
void solve() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] != '.') {
        if (s[i][j] == s[i + 1][j]) {
          p1.push_back(make_pair(i, j));
          p2.push_back(make_pair(i + 1, j));
        }
        if (s[i][j] == s[i][j + 1]) {
          p1.push_back(make_pair(i, j));
          p2.push_back(make_pair(i, j + 1));
        }
      }
  assert(p1.size() == 28);
  memset(color, -1, sizeof(color));
  rec(0, 0);
  for (int i = 1; i <= 7; i++) answer *= i;
  printf("%lld\n", answer);
  for (int i = 0; i < n; i++) printf("%s\n", ser[i]);
}
void printAns() {}
void stress() {}
int main() {
  if (1) {
    int k = 1;
    for (int tt = 0; tt < k; tt++) {
      read();
      solve();
      printAns();
    }
  } else {
    stress();
  }
  return 0;
}
