#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  string ss[h];
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    ss[i] = s;
  }
  int x[8] = {1, 1, 1, 0, 0, -1, -1, -1};
  int y[8] = {1, 0, -1, 1, -1, 1, 0, -1};
  int m = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ss[i][j] == '#') continue;
      int n = 0;
      for (int k = 0; k < 8; k++) {
        int ax = j + x[k];
        int ay = i + y[k];
        if (ax < 0 || ax >= w) continue;
        if (ay < 0 || ay >= h) continue;
        if (ss[ax][ay] == '#') {
          n++;
        }
      }
      ss[i][j] = char(n + '0');
    }
  }
  for (int i = 0; i < h; i++) {
    cout << ss[i] << endl;
  }
}
