#include <bits/stdc++.h>
using namespace std;
int h = 0, w = 0;
char s[51][51];
int checkmine(unsigned, unsigned);
int main() {
  int i, j;
  cin >> h >> w;
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      cin >> s[j][i];
    }
  }
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      int check = checkmine(j, i);
      if (check == 0) {
        cout << "#";
      } else {
        char out = '0' + check;
        cout << out;
      }
    }
    cout << endl;
  }
  return 0;
}
int checkmine(unsigned x, unsigned y) {
  int i, j;
  unsigned count = 0;
  if (s[x][y] == '#') return 0;
  for (i = -1; i <= 1; i++) {
    for (j = -1; j <= 1; j++) {
      if (x + i <= 0 || y + j <= 0) continue;
      if (s[x + i][y + j] == '#') count++;
    }
  }
  return count;
}
