#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int h, w;
  cin >> h >> w;
  string s[h + 3];
  int i, j;
  for (i = 1; i <= h; ++i) {
    cin >> s[i];
  }
  int map[53][53] = {};
  for (i = 0; i <= h; ++i) {
    for (j = 0; j <= w; ++j) {
      if (s[i][j] == '#') {
        map[i][j] += 10;
        map[i - 1][j] += 1;
        map[i + 1][j] += 1;
        map[i][j - 1] += 1;
        map[i][j + 1] += 1;
        map[i - 1][j - 1] += 1;
        map[i - 1][j + 1] += 1;
        map[i + 1][j - 1] += 1;
        map[i + 1][j + 1] += 1;
      }
    }
  }
  for (i = 1; i <= h; ++i) {
    for (j = 0; j < w; ++j) {
      if (map[i][j] >= 10)
        cout << '#';
      else
        cout << map[i][j];
    }
    cout << endl;
  }
  return 0;
}
