#include <bits/stdc++.h>
int main(void) {
  char rowCol[1000][50];
  int numRow, numCol;
  int i, j, k, l;
  int rowColNum[1000][50] = {0};
  if (scanf("%d %d\n", &numRow, &numCol))
    ;
  for (i = 0; i < numRow; i++) {
    if (scanf("%s\n", rowCol[i]))
      ;
  }
  for (i = 0; i < numRow; i++) {
    for (j = 0; j < numCol; j++) {
      if (strncmp("#", &rowCol[i][j], 1) == 0) {
        rowColNum[i][j] = 9;
        for (k = i - 1; k <= i + 1; k++) {
          for (l = j - 1; l <= j + 1; l++) {
            if (k == i && l == j || rowColNum[k][l] == 9) {
              continue;
            }
            rowColNum[k][l] += 1;
          }
        }
      }
    }
  }
  for (i = 0; i < numRow; i++) {
    for (j = 0; j < numCol; j++) {
      if (rowColNum[i][j] == 9) {
        printf("#");
        continue;
      }
      printf("%d", rowColNum[i][j]);
    }
    printf("\n");
  }
  return 0;
}
