#include <bits/stdc++.h>
using namespace std;
int rowN, colN;
char a[100][100], b[100][100];
vector<pair<int, int> > blk;
vector<int> ans, curAns;
vector<int> chClr[256];
bool have[10][10];
bool color(int x, int y, int clr) {
  if (chClr[a[x][y]].empty()) {
    chClr[a[x][y]].push_back(clr);
    return true;
  } else if (have[chClr[a[x][y]].front()][clr]) {
    return false;
  } else {
    have[chClr[a[x][y]].front()][clr] = have[clr][chClr[a[x][y]].front()] =
        true;
    chClr[a[x][y]].push_back(clr);
    return true;
  }
}
void uncolor(int x, int y) {
  if (chClr[a[x][y]].size() == 2) {
    have[chClr[a[x][y]].front()][chClr[a[x][y]].back()] =
        have[chClr[a[x][y]].back()][chClr[a[x][y]].front()] = false;
  }
  chClr[a[x][y]].pop_back();
}
int cnt;
void fun(int id) {
  if (id == blk.size()) {
    cnt++;
    if (ans.empty()) ans = curAns;
    return;
  }
  for (int i = 0; i <= 6; i++) {
    if (color(blk[id].first, blk[id].second, i)) {
      if (color(blk[id].first + 1, blk[id].second, i)) {
        if (color(blk[id].first, blk[id].second + 1, i)) {
          if (color(blk[id].first + 1, blk[id].second + 1, i)) {
            curAns.push_back(i);
            fun(id + 1);
            curAns.pop_back();
            uncolor(blk[id].first + 1, blk[id].second + 1);
          }
          uncolor(blk[id].first, blk[id].second + 1);
        }
        uncolor(blk[id].first + 1, blk[id].second);
      }
      uncolor(blk[id].first, blk[id].second);
    }
  }
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.first + a.second < b.first + b.second;
}
int main() {
  scanf("%d%d", &rowN, &colN);
  for (int i = 1; i <= rowN; i++) {
    char tmp[100];
    gets(tmp);
    for (int j = 1; j <= colN; j++) {
      a[i][j] = getchar();
    }
  }
  memcpy(b, a, sizeof(a));
  for (int i = 1; i <= rowN; i++)
    for (int j = 1; j <= colN; j++)
      if (b[i][j] != '.') {
        blk.push_back(make_pair(i, j));
        b[i][j] = b[i][j + 1] = b[i + 1][j] = b[i + 1][j + 1] = '.';
      }
  sort(blk.begin(), blk.end(), cmp);
  fun(0);
  cout << cnt << endl;
  for (int i = 0; i < ans.size(); i++) {
    int x = blk[i].first, y = blk[i].second;
    b[x][y] = b[x][y + 1] = b[x + 1][y] = b[x + 1][y + 1] = ans[i] + '0';
  }
  for (int i = 1; i <= rowN; i++) {
    for (int j = 1; j <= colN; j++) putchar(b[i][j]);
    puts("");
  }
  return 0;
}
