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