#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> mine(h);
  for (int i = 0; i < h; i++) {
    cin >> mine[i];
  }
  vector<vector<int>> ans(w, vector<int>(h, 0));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (mine[i][j] == '#') {
        if (i - 1 >= 0 && j - 1 >= 0) {
          if (mine[i - 1][j - 1] != '#') {
            ans[i - 1][j - 1]++;
          }
        }
        if (i - 1 >= 0) {
          if (mine[i - 1][j] != '#') {
            ans[i - 1][j]++;
          }
        }
        if (i - 1 >= 0 && j + 1 <= w - 1) {
          if (mine[i - 1][j + 1] != '#') {
            ans[i - 1][j + 1]++;
          }
        }
        if (j - 1 >= 0) {
          if (mine[i][j - 1] != '#') {
            ans[i][j - 1]++;
          }
        }
        if (j + 1 <= w - 1) {
          if (mine[i][j + 1] != '#') {
            ans[i][j + 1]++;
          }
        }
        if (i + 1 <= h - 1 && j - 1 >= 0) {
          if (mine[i + 1][j - 1] != '#') {
            ans[i + 1][j - 1]++;
          }
        }
        if (i + 1 <= h - 1) {
          if (mine[i + 1][j] != '#') {
            ans[i + 1][j]++;
          }
        }
        if (i + 1 <= h - 1 && j + 1 <= w - 1) {
          if (mine[i + 1][j + 1] != '#') {
            ans[i + 1][j + 1]++;
          }
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ans[i][j] != 0) {
        cout << ans[i][j];
      } else {
        if (mine[i][j] == '#') {
          cout << "#";
        } else {
          cout << "0";
        }
      }
    }
    cout << endl;
  }
  return 0;
}
