#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long n, m, vans = 0;
bool vis[35][35], tk[35], vis2[7][7], prt;
pair<long long, long long> adj[35][35], tsqs[35];
vector<pair<long long, long long> > squ;
char grid[35][35], ans[35][35], fans[35][35];
bool check() {
  long long i, j, x, y, a, b;
  for (i = 0; i < 7; i++) {
    a = tsqs[i].first;
    b = tsqs[i].second;
    x = squ[a].first;
    y = squ[a].second;
    ans[x][y] = ans[x + 1][y] = ans[x][y + 1] = ans[x + 1][y + 1] = ('0' + i);
    x = squ[b].first;
    y = squ[b].second;
    ans[x][y] = ans[x + 1][y] = ans[x][y + 1] = ans[x + 1][y + 1] = ('0' + i);
  }
  memset(vis2, false, sizeof(vis2));
  memset(vis, false, sizeof(vis));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (grid[i][j] != '.' && (!vis[i][j])) {
        vis[i][j] = vis[adj[i][j].first][adj[i][j].second] = true;
        if (vis2[min(ans[i][j] - '0',
                     ans[adj[i][j].first][adj[i][j].second] - '0')]
                [max(ans[i][j] - '0',
                     ans[adj[i][j].first][adj[i][j].second] - '0')]) {
          return false;
        }
        vis2[min(ans[i][j] - '0', ans[adj[i][j].first][adj[i][j].second] - '0')]
            [max(ans[i][j] - '0',
                 ans[adj[i][j].first][adj[i][j].second] - '0')] = true;
      }
    }
  }
  return true;
}
void dfs(long long x) {
  long long i, j;
  if (x == 7) {
    if (check()) {
      vans += 5040;
      if (!prt) {
        prt = true;
        for (i = 1; i <= n; i++) {
          for (j = 1; j <= m; j++) {
            fans[i][j] = ans[i][j];
          }
        }
      }
    }
    return;
  }
  for (i = 0; i < 14; i++) {
    if (!tk[i]) {
      tk[i] = true;
      tsqs[x].first = i;
      break;
    }
  }
  for (i = 0; i < 14; i++) {
    if (!tk[i]) {
      tk[i] = true;
      tsqs[x].second = i;
      dfs(x + 1);
      tk[i] = false;
    }
  }
  tk[tsqs[x].first] = false;
  return;
}
int main() {
  long long i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> grid[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (grid[i][j] == '.') {
        adj[i][j] = make_pair(-1, -1);
        continue;
      }
      if (grid[i - 1][j] == grid[i][j]) {
        adj[i][j] = make_pair(i - 1, j);
      } else if (grid[i + 1][j] == grid[i][j]) {
        adj[i][j] = make_pair(i + 1, j);
      } else if (grid[i][j - 1] == grid[i][j]) {
        adj[i][j] = make_pair(i, j - 1);
      } else {
        adj[i][j] = make_pair(i, j + 1);
      }
      if (vis[i][j]) {
        continue;
      }
      squ.push_back(make_pair(i, j));
      vis[i + 1][j] = vis[i][j + 1] = vis[i + 1][j + 1] = vis[i][j] = true;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      ans[i][j] = grid[i][j];
    }
  }
  dfs(0);
  cout << vans << endl;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cout << fans[i][j];
    }
    puts("");
  }
  return 0;
}
