#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> m(H + 2, vector<char>(W + 2, '@'));
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; j++) cin >> m[i][j];
  int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
  vector<vector<int>> v(H + 2, vector<int>(W + 2, -1));
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; j++) {
      if (m[i][j] == '@') continue;
      int cnt = 0;
      for (int k = 0; k < 9; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (m[nx][ny] == '#') cnt++;
      }
      v[i][j] = cnt;
    }
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; j++) {
      if (v[i][j] == -1)
        cout << '#';
      else
        cout << v[i][j];
    }
    cout << endl;
  }
}
