#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  char a[h][w];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
      cout << "a";
    }
  }
  int counter = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        cout << '#';
      } else {
        counter = 0;
        if (i - 1 >= 0) {
          if (j - 1 >= 0 && a[i - 1][j - 1] == '#') counter++;
          if (a[i - 1][j] == '#') counter++;
          if (j + 1 < w && a[i - 1][j + 1] == '#') counter++;
        }
        if (j - 1 >= 0 && a[i][j - 1] == '#') counter++;
        if (j + 1 < w && a[i][j + 1] == '#') counter++;
        if (i + 1 < h) {
          if (j - 1 >= 0 && a[i + 1][j - 1] == '#') counter++;
          if (a[i + 1][j] == '#') counter++;
          if (j + 1 < w && a[i + 1][j + 1] == '#') counter++;
        }
        cout << counter;
      }
    }
    cout << endl;
  }
}
