#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  int ni, nj;
  vector<string> s(W);
  for (int i = 0; i < W; i++) cin >> s[i];
  vector<int> dx = {0, 1, 1, 1, 0, -1, -1, -1};
  vector<int> dy = {1, 1, 0, -1, -1, -1, 0, 1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i].at(j) == '#') continue;
      int num = 0;
      for (int k = 0; k < 8; k++) {
        ni = i + dy.at(k);
        nj = j + dx.at(k);
        if (ni < 0 || ni > H - 1 || nj < 0 || nj > W - 1) continue;
        if (s[ni].at(nj) == '#') num++;
      }
      s[i].at(j) = char(num + '0');
    }
  }
  for (int i = 0; i < H; i++) {
    cout << s[i] << endl;
  }
}
