#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int MOD = 1000000007;
int main() {
  int h, w, count;
  cin >> h >> w;
  vector<string> s(h);
  int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[8] = {0, 1, 0, -1, -1, -1, 1, 1};
  vector<string> ans(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] == '#') {
        ans[i][j] = '#';
        continue;
      }
      count = 0;
      for (int dir = 0; dir < (8); ++dir) {
        int nh = i + dx[dir];
        int nw = j + dy[dir];
        if (nh < 0 || nh >= h || nw < 0 || nw >= w) continue;
        if (s[nh][nw] == '#') count++;
      }
      ans[i][j] = '0' + count;
    }
  }
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      cout << ans[i][j];
    }
    cout << endl;
  }
}
