#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[50][50];
int countMines(int i, int j) {
  int count = 0;
  for (int k = i - 1; k <= i + 1; k++) {
    for (int l = j - 1; l <= j + 1; l++) {
      if (k < 0 || k >= H || l < 0 || l >= W) {
        continue;
      }
      if (S[k][l] == '#') {
        count++;
      }
    }
  }
  return count;
}
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] == '#') {
        continue;
      }
      S[i][j] = countMines(i, j) + '0';
    }
  }
  for (int i = 0; i < H; i++) {
    printf("%s\n", S[i]);
  }
  return 0;
}
