#include <bits/stdc++.h>
using namespace std;
char a[51][51];
int b[51][51];
int main() {
  int h, w;
  cin >> h >> w;
  memset(b, 0, sizeof(b));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
      if (i <= h && i >= 0 && j <= w && j >= 0) {
        if (a[i][j] == '#') {
          b[i - 1][j - 1]++;
          b[i - 1][j]++;
          b[i - 1][j + 1]++;
          b[i][j - 1]++;
          b[i][j + 1]++;
          b[i + 1][j - 1]++;
          b[i + 1][j]++;
          b[i + 1][j + 1]++;
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#')
        cout << a[i][j];
      else
        cout << b[i][j];
    }
    cout << endl;
  }
  return 0;
}
