#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int i, j, k, H, W, tmp;
  char c;
  vector<char> S;
  vector<char> A;
  scanf("%d %d", &H, &W);
  int dir[9] = {{-W - 1}, {-W}, {-W + 1}, {-1}, {+1}, {W - 1}, {W}, {W + 1}};
  for (i = 0; i < H * W; i++) {
    scanf("%c", &c);
    if (c == '#') {
      S.push_back(c);
      A.push_back('#');
    } else if (c == '.') {
      S.push_back(c);
      A.push_back('0');
    } else {
      i--;
    }
  }
  for (int i = 0; i < (H * W); i++) {
    if (A.at(i) == '#') {
      for (int j = 0; j < (8); j++) {
        if (i + dir[j] >= 0 && i + dir[j] < H * W) {
          A.at(i + dir[j])++;
        }
      }
    }
  }
  for (int i = 0; i < (W * H); i++) {
    printf("%c", A.at(i));
    if (i % W == W - 1) {
      printf("\n");
    }
  }
  return 0;
}
