#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char bom[50][50];
  for (int y = 0; y != h; y++) {
    for (int x = 0; x != w; x++) {
      cin >> bom[x][y];
    }
  }
  int countBomAtack = 0;
  for (int i = 0; i != h; i++) {
    for (int j = 0; j != w; j++) {
      if (bom[j][i] == '#') {
        cout << '#';
        goto _skip;
      }
      if (bom[j - 1][i - 1] == '#') {
        countBomAtack += 1;
      }
      if (bom[j][i - 1] == '#') {
        countBomAtack += 1;
      }
      if (bom[j][i + 1] == '#') {
        countBomAtack += 1;
      }
      if (bom[j - 1][i] == '#') {
        countBomAtack += 1;
      }
      if (bom[j + 1][i] == '#') {
        countBomAtack += 1;
      }
      if (bom[j - 1][i + 1] == '#') {
        countBomAtack += 1;
      }
      if (bom[j + 1][i - 1] == '#') {
        countBomAtack += 1;
      }
      if (bom[j + 1][i + 1] == '#') {
        countBomAtack += 1;
      }
      cout << countBomAtack;
    _skip:
      countBomAtack = 0;
    }
    cout << '\n';
  }
  return 0;
}
