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