#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W, '-'));
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) cin >> S.at(i).at(j);
  const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == '#') continue;
      int count = 0;
      for (int k = 0; k < 8; k++) {
        int x = i + dx[k];
        int y = j + dy[k];
        if (x < 0 || H <= x) continue;
        if (y < 0 || W <= y) continue;
        if (S.at(x).at(y) == '#') count++;
      }
      S.at(i).at(j) = char(count + '0');
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << S.at(i).at(j);
    }
    cout << endl;
  }
  puts("sss");
}
