#include <bits/stdc++.h>
using namespace std;
int check_side(int x, int mx) {
  if (x <= 0) return 0;
  if (x >= mx) return mx - 1;
  return x;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<char> > v(n, vector<char>(m));
  vector<vector<int> > vi(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
      if (v[i][j] == '#') {
        for (int k = -1; k < 2; k++)
          for (int l = -1; l < 2; l++) {
            vi[check_side(i + k, n)][check_side(j + l, m)]++;
          }
      }
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '#') {
        cout << '#';
      } else {
        cout << vi[i][j];
      }
    }
    cout << endl;
  }
}
