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