#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, m, nxt, ans;
char c[35][35];
bool vis[7][7], f[35][35], fv[35][35];
pair<long long, long long> p[30];
long long to[35][35];
long long col[30];
long long a[35][35], b[35][35];
long long ct[10];
void dfs(long long x) {
  if (x == 15) {
    if (!ans) {
      for (long long i = 1; i <= 14; i++) {
        for (long long j = p[i].first; j <= p[i].first + 1; j++) {
          for (long long k = p[i].second; k <= p[i].second + 1; k++) {
            a[j][k] = b[j][k];
          }
        }
      }
    }
    ans++;
    return;
  }
  for (long long i = 0; i <= nxt - (nxt == 7); i++)
    if (i == nxt || ct[i] == 0) {
      vector<pair<long long, long long> > vp;
      bool ff = 1;
      for (long long j = p[x].first; j <= p[x].first + 1; j++) {
        for (long long k = p[x].second; k <= p[x].second + 1; k++)
          b[j][k] = i, fv[j][k] = 1;
      }
      for (long long j = p[x].first; j <= p[x].first + 1; j++) {
        for (long long k = p[x].second; k <= p[x].second + 1; k++)
          if (to[j][k]) {
            long long tj, tk;
            tj = j - (to[j][k] == 2) + (to[j][k] == 4);
            tk = k - (to[j][k] == 1) + (to[j][k] == 3);
            if (!fv[tj][tk] ||
                (j >= tj && k >= tk && tj >= p[x].first && tk >= p[x].second))
              continue;
            if (vis[b[tj][tk]][i]) {
              ff = 0;
              break;
            }
            vis[b[tj][tk]][i] = vis[i][b[tj][tk]] = 1;
            vp.emplace_back(make_pair(b[tj][tk], i));
          }
      }
      if (ff) {
        if (i != nxt) ct[i] = 1;
        long long tn = nxt;
        nxt += i == nxt;
        dfs(x + 1);
        nxt = tn;
        ct[i] = 0;
      }
      for (auto u : vp) {
        vis[u.first][u.second] = vis[u.second][u.first] = 0;
      }
      for (long long j = p[x].first; j <= p[x].first + 1; j++) {
        for (long long k = p[x].second; k <= p[x].second + 1; k++)
          b[j][k] = 0, fv[j][k] = 0;
      }
    }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (c[i][j] != '.' &&
          (c[i][j] == c[i - 1][j] || c[i][j] == c[i][j - 1])) {
        to[i][j] = 1 + (c[i][j] == c[i - 1][j]);
      }
      if (c[i][j] != '.' &&
          (c[i][j] == c[i + 1][j] || c[i][j] == c[i][j + 1])) {
        to[i][j] = 3 + (c[i][j] == c[i + 1][j]);
      }
    }
  }
  long long cnt = 0;
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j < m; j++) {
      if (!f[i][j] && c[i][j] != '.' && c[i + 1][j] != '.' &&
          c[i][j + 1] != '.' && c[i + 1][j + 1] != '.') {
        f[i][j] = f[i + 1][j] = f[i][j + 1] = f[i + 1][j + 1] = 1;
        p[++cnt] = make_pair(i, j);
      }
    }
  }
  dfs(1);
  for (long long i = 1; i <= 7; i++) ans *= i;
  cout << ans << '\n';
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (c[i][j] == '.') {
        cout << '.';
      } else
        cout << a[i][j];
    }
    cout << '\n';
  }
  return 0;
}
