#include <bits/stdc++.h>
using namespace std;
const int _7 = 5040;
const int maxn = 100;
int n, m, N, A[maxn][maxn];
struct Tcxx {
  int x, y;
} B[maxn];
namespace Ninit {
bool U[maxn][maxn];
char s[maxn];
int Mp(char x) {
  return x == '.' ? -1 : 'a' <= x && x <= 'z' ? x - 'a' : x - 'A' + 26;
}
void init() {
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (j = 1; j <= m; ++j) A[i][j] = Mp(s[j]);
  }
  for (i = 1; i < n; ++i)
    for (j = 1; j < m; ++j)
      if (!U[i][j] && A[i][j] != -1) {
        B[N].x = i, B[N].y = j, N++;
        U[i][j] = U[i + 1][j] = U[i][j + 1] = U[i + 1][j + 1] = true;
      }
}
}  // namespace Ninit
namespace Nsolve {
long long tot;
int Ot[maxn][maxn];
namespace Nsearch {
bool U[maxn], dom[maxn][maxn];
int a[maxn][maxn];
inline void paint(int x, int y, int c) {
  a[x][y] = a[x + 1][y] = a[x][y + 1] = a[x + 1][y + 1] = c;
}
bool check() {
  int i, j, p, q;
  memset(dom, 0, sizeof dom);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j)
      if (A[i][j] != -1) {
        if (j < m && A[i][j + 1] == A[i][j]) {
          p = a[i][j + 1], q = a[i][j];
          if (p > q) swap(p, q);
          if (dom[p][q])
            return false;
          else
            dom[p][q] = true;
        }
        if (i < n && A[i + 1][j] == A[i][j]) {
          p = a[i + 1][j], q = a[i][j];
          if (p > q) swap(p, q);
          if (dom[p][q])
            return false;
          else
            dom[p][q] = true;
        }
      }
  return true;
}
void dfs(int x) {
  int i, u;
  if (x == 7) {
    if (!check()) return;
    memcpy(Ot, a, sizeof Ot), tot += _7;
    return;
  }
  for (u = 0; u < N; ++u)
    if (!U[u]) break;
  for (i = u + 1; i < N; ++i)
    if (!U[i]) {
      paint(B[u].x, B[u].y, x), paint(B[i].x, B[i].y, x);
      U[u] = U[i] = true, dfs(x + 1), U[u] = U[i] = false;
    }
}
void solve() {
  memset(a, 0xff, sizeof a);
  dfs(0);
}
}  // namespace Nsearch
void solve() {
  int i, j;
  Nsearch::solve();
  cout << tot << endl;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j)
      Ot[i][j] == -1 ? printf(".") : printf("%d", Ot[i][j]);
    printf("\n");
  }
}
}  // namespace Nsolve
int main() {
  Ninit::init();
  Nsolve::solve();
  return 0;
}
