#include <bits/stdc++.h>
struct Square {
  int number;
  bool contains_domino;
  Square() : contains_domino(false) {}
  Square(int n) : number(n), contains_domino(false) {}
};
const int number_of_squares = 14;
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::string> field_to_char;
  std::vector<std::pair<int, int> > domino_to_squares;
  std::vector<Square> squares(number_of_squares);
  std::map<int, std::map<int, Square*> > field_to_square;
  std::map<int, std::map<int, bool> > field_is_on_upper_side_of_square;
  std::map<int, std::map<int, bool> > field_is_on_left_side_of_square;
  int number_of_labeled_squares = 0;
  int squares_index = 0;
  for (int i = 0; i < n; ++i) {
    std::string line;
    std::cin >> line;
    field_to_char.push_back(line);
    for (int j = 0; j < m; ++j) {
      if (field_to_char[i][j] == '.') continue;
      field_is_on_upper_side_of_square[i][j] =
          (i == 0 || field_to_char[i - 1][j] == '.' ||
           !field_is_on_upper_side_of_square[i - 1][j]);
      field_is_on_left_side_of_square[i][j] =
          (j == 0 || field_to_char[i][j - 1] == '.' ||
           !field_is_on_left_side_of_square[i][j - 1]);
      Square* square;
      if (field_is_on_upper_side_of_square[i][j] &&
          field_is_on_left_side_of_square[i][j]) {
        square = &squares[squares_index];
        square->number = squares_index++;
      } else if (!field_is_on_upper_side_of_square[i][j])
        square = field_to_square[i - 1][j];
      else
        square = field_to_square[i][j - 1];
      field_to_square[i][j] = square;
      if (i > 0 && field_to_char[i][j] == field_to_char[i - 1][j]) {
        if (!field_is_on_upper_side_of_square[i][j]) {
          square->contains_domino = true;
          number_of_labeled_squares++;
        }
        domino_to_squares.push_back(
            std::make_pair(field_to_square[i - 1][j]->number, square->number));
      }
      if (j > 0 && field_to_char[i][j] == field_to_char[i][j - 1]) {
        if (!field_is_on_left_side_of_square[i][j]) {
          square->contains_domino = true;
          number_of_labeled_squares++;
        }
        domino_to_squares.push_back(
            std::make_pair(field_to_square[i][j - 1]->number, square->number));
      }
    }
  }
  std::vector<int> label_to_square;
  for (int i = 0; i < number_of_squares; ++i)
    if (squares[i].contains_domino) label_to_square.push_back(i);
  for (int i = 0; i < number_of_squares; ++i)
    if (!squares[i].contains_domino) label_to_square.push_back(i);
  int square_to_label[number_of_squares];
  int solution_square_to_label[number_of_squares];
  long long number_of_solutions = 0;
  int numbers_of_dominos[number_of_squares * 2];
  int dominos_enumeration[7][7];
  for (int i = 0, n = 0; i < 7; ++i)
    for (int j = i; j < 7; ++j)
      dominos_enumeration[i][j] = dominos_enumeration[j][i] = n++;
  for (;;) {
    memset(square_to_label, 0, sizeof(square_to_label));
    for (int i = 0; i < number_of_squares; ++i)
      square_to_label[label_to_square[i]] = i % (number_of_squares / 2);
    memset(numbers_of_dominos, 0, sizeof(numbers_of_dominos));
    int k = 0;
    for (; k < domino_to_squares.size(); ++k) {
      int label1 = square_to_label[domino_to_squares[k].first];
      int label2 = square_to_label[domino_to_squares[k].second];
      if (++numbers_of_dominos[dominos_enumeration[label1][label2]] > 1) break;
    }
    if (k == domino_to_squares.size()) {
      if (!number_of_solutions)
        memcpy(solution_square_to_label, square_to_label,
               sizeof(square_to_label));
      ++number_of_solutions;
    }
    k = label_to_square.size() - 2;
    for (; k >= number_of_labeled_squares &&
           label_to_square[k] > label_to_square[k + 1];
         --k)
      ;
    if (k < number_of_labeled_squares) break;
    int l = label_to_square.size() - 1;
    for (; l > number_of_labeled_squares &&
           label_to_square[k] > label_to_square[l];
         --l)
      ;
    std::swap(label_to_square[k], label_to_square[l]);
    for (l = 1; l <= (label_to_square.size() - k - 1) / 2; ++l)
      std::swap(label_to_square[k + l],
                label_to_square[label_to_square.size() - l]);
  }
  for (int i = number_of_squares / 2; i >= 2; --i) number_of_solutions *= i;
  for (int i = number_of_squares / 2 - number_of_labeled_squares; i >= 2; --i)
    number_of_solutions /= i;
  for (int i = 1; i <= number_of_squares / 2 - number_of_labeled_squares; ++i)
    number_of_solutions /= 2;
  std::cout << number_of_solutions << std::endl;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (field_to_char[i][j] == '.')
        std::cout << field_to_char[i][j];
      else
        std::cout << solution_square_to_label[field_to_square[i][j]->number];
    }
    std::cout << std::endl;
  }
  return 0;
}
