#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  char s[50 + 10][50 + 10] = {};
  cin >> H >> W;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (s[i][j] == '#') continue;
      int b = 0;
      if (s[i - 1][j - 1] == '#') b++;
      if (s[i - 1][j] == '#') b++;
      if (s[i - 1][j + 1] == '#') b++;
      if (s[i][j - 1] == '#') b++;
      if (s[i][j + 1] == '#') b++;
      if (s[i + 1][j - 1] == '#') b++;
      if (s[i + 1][j] == '#') b++;
      if (s[i + 1][j + 1] == '#') b++;
      s[i][j] = b;
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      printf("%s", s[i][j]);
    }
    cout << endl;
  }
}
