#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
char a[32][32];
bool used[7][7];
int cnt;
int xs[32], ys[32];
int id[32][32];
int sid[32][32];
char p[32][32];
int dom;
int col_cnt[7];
int col[32];
int num[32][32];
int fc[32];
int sc[32];
int n, m;
int ans = 0;
void draw_ans(int k) {
  memset(p, '.', sizeof(p));
  for (int i = 0; i < int(k); i++) {
    for (int dx = 0; dx < int(2); dx++) {
      for (int dy = 0; dy < int(2); dy++) {
        p[xs[i] + dx][ys[i] + dy] = char(col[i] + '0');
      }
    }
  }
}
void rec(int k) {
  if (k == 14) {
    if (ans == 0) draw_ans(k);
    ans++;
    return;
  }
  int x = xs[k];
  int y = ys[k];
  int tmp[32];
  memcpy(tmp, fc, sizeof(fc));
  int qx[4];
  int qy[4];
  for (int c = 0; c < int(7); c++) {
    if (col_cnt[c] == 2) continue;
    bool ok = true;
    int cq = 0;
    for (int dx = 0; dx < int(2); dx++) {
      for (int dy = 0; dy < int(2); dy++) {
        int t = id[x + dx][y + dy];
        if (fc[t] == -1) {
          fc[t] = c;
        } else {
          if (used[((fc[t]) < (c) ? (fc[t]) : (c))]
                  [((fc[t]) > (c) ? (fc[t]) : (c))]) {
            ok = false;
            break;
          }
          qx[cq] = ((fc[t]) < (c) ? (fc[t]) : (c));
          qy[cq] = ((fc[t]) > (c) ? (fc[t]) : (c));
          used[qx[cq]][qy[cq]] = true;
          cq++;
        }
      }
      if (!ok) break;
    }
    for (int i = 0; i < int(cq); i++) {
      used[qx[i]][qy[i]] = false;
    }
    if (!ok) {
      memcpy(fc, tmp, sizeof(fc));
      continue;
    }
    cq = 0;
    memcpy(fc, tmp, sizeof(fc));
    for (int dx = 0; dx < int(2); dx++) {
      for (int dy = 0; dy < int(2); dy++) {
        int t = id[x + dx][y + dy];
        if (fc[t] == -1) {
          fc[t] = c;
        } else {
          sc[t] = c;
          qx[cq] = ((fc[t]) < (c) ? (fc[t]) : (c));
          qy[cq] = ((fc[t]) > (c) ? (fc[t]) : (c));
          used[qx[cq]][qy[cq]] = true;
          cq++;
        }
      }
    }
    col[k] = c;
    col_cnt[c]++;
    rec(k + 1);
    col_cnt[c]--;
    memcpy(fc, tmp, sizeof(fc));
    for (int i = 0; i < int(cq); i++) {
      used[qx[i]][qy[i]] = false;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < int(n); i++) {
    string s;
    cin >> s;
    for (int j = 0; j < int(m); j++) a[i][j] = s[j];
  }
  memset(id, 255, sizeof(id));
  memset(sid, 255, sizeof(sid));
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(m); j++) {
      if (id[i][j] != -1) continue;
      if (a[i][j] == '.') continue;
      if (i < n - 1 && a[i][j] == a[i + 1][j]) {
        id[i][j] = id[i + 1][j] = dom++;
      }
      if (j < m - 1 && a[i][j] == a[i][j + 1]) {
        id[i][j] = id[i][j + 1] = dom++;
      }
    }
  }
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(m); j++) {
      if (sid[i][j] != -1) continue;
      bool ok = true;
      for (int ii = 0; ii < int(2); ii++) {
        for (int jj = 0; jj < int(2); jj++) {
          if (i + ii >= n || j + jj >= m || a[i + ii][j + jj] == '.') {
            ok = false;
          }
        }
      }
      if (ok) {
        for (int ii = 0; ii < int(2); ii++) {
          for (int jj = 0; jj < int(2); jj++) {
            sid[i + ii][j + jj] = cnt;
          }
        }
        xs[cnt] = i;
        ys[cnt] = j;
        cnt++;
      }
    }
  }
  assert(cnt == 14);
  memset(num, 255, sizeof(num));
  memset(fc, 255, sizeof(fc));
  rec(0);
  cout << ans << endl;
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(m); j++) {
      cout << p[i][j];
    }
    cout << endl;
  }
  cerr << clock() << endl;
  return 0;
}
