#include <bits/stdc++.h>
using namespace std;
int W, H;
char field[51][51];
int dirx[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int diry[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
char cntBomb(int x, int y) {
  int cnt = 0;
  for (int i = 0; i < 9; i++) {
    if (x + dirx[i] >= 0 && x + dirx[i] < W && y + diry[i] >= 0 &&
        y + diry[i] < W) {
      if (field[x + dirx[i]][y + diry[i]] == '#') cnt++;
    }
  }
  return '0' + (cnt);
}
int main(void) {
  cin >> H >> W;
  for (int i = 0; i < H; i++) cin >> field[i];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '.') {
        field[i][j] = cntBomb(i, j);
      }
    }
  }
  for (int i = 0; i < H; i++) {
    cout << field[i] << endl;
  }
}
