#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 < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int b;
      if (s[i][j] == '#') {
        s[i][j] = '#';
      } else {
        for (int k = -1; k < 2; k++) {
          for (int l = 0; l < 2; l++) {
            if (s[i + k][j + l] == '#') {
              b++;
            }
          }
        }
        s[i][j] = b;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << s[i][j];
    }
    cout << ' ' << endl;
  }
}
