#include <bits/stdc++.h>
int bomb[50][50];
int main() {
  int row, column;
  int number;
  scanf("%d%d", &row, &column);
  getchar();
  for (int i = 0; i < row; i++) {
    for (int j = 0; j < column; j++) {
      scanf("%c", &bomb[i][j]);
    }
    getchar();
  }
  if (row > 1 && column > 1) {
    for (int i = 0; i < row; i++) {
      for (int j = 0; j < column; j++) {
        number = 0;
        if (bomb[i][j] == '#')
          printf("%c", '#');
        else if (bomb[i][j] == '.') {
          if (i == 0) {
            if (j == 0) {
              if (bomb[0][1] == '#') number++;
              if (bomb[1][0] == '#') number++;
              if (bomb[1][1] == '#') number++;
              printf("%d", number);
            } else if (j == column - 1) {
              if (bomb[0][column - 2] == '#') number++;
              if (bomb[1][column - 1] == '#') number++;
              if (bomb[1][column - 2] == '#') number++;
              printf("%d", number);
            } else {
              if (bomb[0][j - 1] == '#') number++;
              if (bomb[0][j + 1] == '#') number++;
              if (bomb[1][j - 1] == '#') number++;
              if (bomb[1][j] == '#') number++;
              if (bomb[1][j + 1] == '#') number++;
              printf("%d", number);
            }
          } else if (i == row - 1) {
            if (j == 0) {
              if (bomb[row - 1][1] == '#') number++;
              if (bomb[row - 2][0] == '#') number++;
              if (bomb[row - 2][1] == '#') number++;
              printf("%d", number);
            } else if (j == column - 1) {
              if (bomb[row - 1][column - 2] == '#') number++;
              if (bomb[row - 2][column - 1] == '#') number++;
              if (bomb[row - 2][column - 2] == '#') number++;
              printf("%d", number);
            } else {
              if (bomb[row - 1][j - 1] == '#') number++;
              if (bomb[row - 1][j + 1] == '#') number++;
              if (bomb[row - 2][j - 1] == '#') number++;
              if (bomb[row - 2][j] == '#') number++;
              if (bomb[row - 2][j + 1] == '#') number++;
              printf("%d", number);
            }
          } else {
            if (j == 0) {
              if (bomb[i - 1][0] == '#') number++;
              if (bomb[i + 1][0] == '#') number++;
              if (bomb[i - 1][1] == '#') number++;
              if (bomb[i][1] == '#') number++;
              if (bomb[i + 1][1] == '#') number++;
              printf("%d", number);
            } else if (j == column - 1) {
              if (bomb[i - 1][column - 1] == '#') number++;
              if (bomb[i + 1][column - 1] == '#') number++;
              if (bomb[i - 1][column - 2] == '#') number++;
              if (bomb[i][column - 2] == '#') number++;
              if (bomb[i + 1][column - 2] == '#') number++;
              printf("%d", number);
            } else {
              if (bomb[i - 1][j - 1] == '#') number++;
              if (bomb[i - 1][j] == '#') number++;
              if (bomb[i - 1][j + 1] == '#') number++;
              if (bomb[i][j - 1] == '#') number++;
              if (bomb[i][j + 1] == '#') number++;
              if (bomb[i + 1][j - 1] == '#') number++;
              if (bomb[i + 1][j] == '#') number++;
              if (bomb[i + 1][j + 1] == '#') number++;
              printf("%d", number);
            }
          }
        }
      }
      printf("\n");
    }
  } else {
    if (row == 1 && column == 1)
      printf("%c\n", bomb[0][0]);
    else if (row == 1 && column == 2) {
      if (bomb[0][0] == '#' && bomb[0][1] == '#')
        printf("##\n");
      else if (bomb[0][0] == '.' && bomb[0][1] == '#')
        printf("1#\n");
      else if (bomb[0][0] == '#' && bomb[0][1] == '.')
        printf("#1\n");
    } else if (row == 2 && column == 1) {
      if (bomb[0][0] == '#' && bomb[1][0] == '#')
        printf("#\n#\n");
      else if (bomb[0][0] == '.' && bomb[1][0] == '#')
        printf("1\n#\n");
      else if (bomb[0][0] == '#' && bomb[1][0] == '.')
        printf("#\n1\n");
    }
  }
}
