#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  int field[H][W];
  for (int i = 0; i < H; i++) {
    string line;
    cin >> line;
    for (int s = 0; s < W; s++) {
      field[i][s] = line.at(s);
    }
  }
  for (int i = 0; i < H; i++) {
    for (int s = 0; s < W; s++) {
      if (field[i][s] == '#') {
        cout << '#';
      } else {
        int count = 0;
        if (field[i - 1][s - 1] == '#') {
          count++;
        };
        if (field[i - 1][s] == '#') {
          count++;
        };
        if (field[i - 1][s + 1] == '#') {
          count++;
        };
        if (field[i][s - 1] == '#') {
          count++;
        };
        if (field[i][s] == '#') {
          count++;
        };
        if (field[i][s + 1] == '#') {
          count++;
        };
        if (field[i + 1][s - 1] == '#') {
          count++;
        };
        if (field[i + 1][s] == '#') {
          count++;
        };
        if (field[i + 1][s + 1] == '#') {
          count++;
        };
        cout << count;
      }
    }
    cout << endl;
  }
}
