#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long x, y;
  cin >> x >> y;
  vector<string> s(x);
  for (long long i = 0; i < x; i++) cin >> s[i];
  long long dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
  long long dy[] = {1, -1, 0, 1, -1, 0, 1, -1};
  for (long long i = 0; i < x; i++) {
    for (long long j = 0; j < y; j++) {
      if (s[i][j] == '.') {
        long long cnt = 0;
        for (long long k = 0; k < 8; k++) {
          long long tmpx = i + dx[k];
          long long tmpy = j + dy[k];
          if (s[tmpx][tmpy] == '#') {
            cnt++;
          }
        }
        s[i][j] = '0' + cnt;
      }
    }
  }
  for (long long i = 0; i < x; i++) {
    cout << s[i] << endl;
  }
}
