#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T& x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
int n, m, ans, k;
char a[32][32];
int u[7][7];
int uu[32][32];
int col[32][32];
int xy[102][4][2];
int aa[32][32];
int b[32][32];
int cnt[7];
int pa[32][32][2];
void rec(int s, int ma) {
  if (s == k) {
    if (!ans) {
      memcpy(aa, b, sizeof(b));
    }
    ans++;
    return;
  }
  int tt = min(ma + 1, 7) + 1;
  for (int i = 0; i < (int)(tt); i++) {
    if (!cnt[i]) continue;
    cnt[i]--;
    bool ok = true;
    for (int t = 0; t < (int)(4); t++) {
      int x = xy[s][t][0];
      int y = xy[s][t][1];
      b[x][y] = i;
      uu[x][y]++;
    }
    for (int t = 0; t < (int)(4); t++) {
      int x = xy[s][t][0];
      int y = xy[s][t][1];
      int xn = pa[x][y][0];
      int yn = pa[x][y][1];
      if (xn < 0 || xn >= n || yn < 0 || yn >= m) continue;
      if (uu[xn][yn]) {
        if (col[xn][yn] == col[x][y] && (x > xn || (x == xn && y > yn)))
          continue;
        if (a[x][y] != a[xn][yn]) continue;
        int c1 = b[x][y];
        int c2 = b[xn][yn];
        if (c1 > c2) swap(c1, c2);
        if (u[c1][c2]) ok = false;
        u[c1][c2]++;
      }
    }
    if (ok) rec(s + 1, max(ma, i));
    for (int t = 0; t < (int)(4); t++) {
      int x = xy[s][t][0];
      int y = xy[s][t][1];
      int xn = pa[x][y][0];
      int yn = pa[x][y][1];
      if (xn < 0 || xn >= n || yn < 0 || yn >= m) continue;
      if (uu[xn][yn]) {
        if (col[xn][yn] == col[x][y] && (x > xn || (x == xn && y > yn)))
          continue;
        if (a[x][y] != a[xn][yn]) continue;
        int c1 = b[x][y];
        int c2 = b[xn][yn];
        if (c1 > c2) swap(c1, c2);
        u[c1][c2]--;
      }
    }
    for (int t = 0; t < (int)(4); t++) {
      int x = xy[s][t][0];
      int y = xy[s][t][1];
      uu[x][y]--;
    }
    cnt[i]++;
  }
}
int main() {
  cout << setiosflags(ios::fixed) << setprecision(10);
  ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%s", a[i]);
  }
  memset(pa, 0xff, sizeof(pa));
  for (int x = 0; x < (int)(n); x++) {
    for (int y = 0; y < (int)(m); y++) {
      if (a[x][y] == '.') continue;
      for (int l = 0; l < (int)(4); l++) {
        int xn = x + dx[l];
        int yn = y + dy[l];
        if (xn < 0 || xn >= n || yn < 0 || yn >= m) continue;
        if (a[x][y] != a[xn][yn]) continue;
        pa[x][y][0] = xn;
        pa[x][y][1] = yn;
      }
    }
  }
  memset((u), 0, sizeof(u));
  memset((uu), 0, sizeof(uu));
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (a[i][j] != '.' && !uu[i][j]) {
        for (int x = 0; x < (int)(2); x++) {
          for (int y = 0; y < (int)(2); y++) {
            uu[i + x][j + y] = true;
            col[i + x][j + y] = k;
            xy[k][x * 2 + y][0] = i + x;
            xy[k][x * 2 + y][1] = j + y;
          }
        }
        k++;
      }
    }
  }
  for (int i = 0; i < (int)(7); i++) {
    cnt[i] = 2;
  }
  memset((uu), 0, sizeof(uu));
  rec(0, -1);
  cout << ans * 5040 << endl;
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (a[i][j] == '.')
        putchar('.');
      else
        printf("%d", aa[i][j]);
    }
    puts("");
  }
  return 0;
}
