#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  string s[50];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int count;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      count = 0;
      if (s[i][j] == '#') {
        continue;
      } else {
        for (int k = -1; k < 2; k++) {
          for (int l = -1; l < 2; l++) {
            if (s[i + k][j + l] == '#') {
              count++;
            }
          }
        }
        s[i][j] = count + '0';
      }
    }
  }
  for (int i = 0; i < h; i++) {
    cout << s[i] << endl;
  }
}
