#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) cin >> S[i];
  const int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  const int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
  for (int x = 0; x < W; x++) {
    for (int y = 0; y < H; y++) {
      if (S[x][y] == '#') continue;
      int num = 0;
      for (int d = 0; d < 8; d++) {
        const int nx = x + dx[d];
        const int ny = y + dy[d];
        if (nx < 0 or W <= nx) continue;
        if (ny < 0 or H <= ny) continue;
        if (S[nx][ny] == '#') num++;
      }
      S[x][y] = char('0' + num);
    }
  }
  for (int i = 0; i < H; i++) cout << S[i] << endl;
}
