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