#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int n = N;
  vector<vector<char>> d(N, vector<char>(M));
  while (n--) {
    string S;
    cin >> S;
    for (int j = 0; j < M; j++) {
      d[N - n][j] = S.at(j);
    }
  }
  vector<vector<char>> ans(N, vector<char>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      int an = -1;
      if (d[i][j] == '#') {
        ans[i][j] = '#';
      } else {
        for (int dx = -1; dx <= 1; dx++) {
          for (int dy = -1; dy <= 1; dy++) {
            int nx = i + dx, ny = j + dy;
            if (0 <= nx && nx < N && 0 <= ny && ny < M && d[nx][ny] == '#') {
              an++;
            }
          }
        }
        ans[i][j] = char(an + '0');
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
}
