#include <bits/stdc++.h>
int main(void) {
  int H, W, i, j, count;
  char S[50][50];
  scanf("%d %d", &H, &W);
  for (i = 0; i < H; i++) {
    scanf("%s", S[i]);
  }
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      count = 0;
      if (S[i][j] == '#') {
        printf("#");
      } else if (S[i][j] == '.') {
        if (S[i][j + 1] == '#') {
          count++;
        }
        if (S[i][j - 1] == '#') {
          count++;
        }
        if (S[i + 1][j] == '#') {
          count++;
        }
        if (S[i - 1][j] == '#') {
          count++;
        }
        if (S[i + 1][j + 1] == '#') {
          count++;
        }
        if (S[i + 1][j - 1] == '#') {
          count++;
        }
        if (S[i - 1][j + 1] == '#') {
          count++;
        }
        if (S[i - 1][j - 1] == '#') {
          count++;
        }
        printf("%d", count);
      }
    }
    printf("\n");
  }
  return 0;
}
