#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1},
          dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  char a[h][w];
  for (int i = 0; i < h; i++) scanf("%s", a[i]);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        printf("#");
        continue;
      }
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (nx < 0 or h <= nx or ny < 0 or w <= ny) continue;
        if (a[nx][ny] == '#') cnt++;
      }
      printf("%d", cnt);
    }
    printf("\n");
  }
  return 0;
}
