#include <bits/stdc++.h>
using namespace std;
int main() {
  string Sa, Sb, Sc, dod;
  int TATE, YOKO;
  cin >> TATE >> YOKO >> Sb;
  dod = ".";
  for (int tate = 0; tate < TATE; tate++) {
    cin >> Sc;
    for (int LOOK = 0; LOOK < YOKO; LOOK++) {
      int sum = 0;
      if (tate == 0) {
        Sa = dod + dod + dod;
        if (LOOK == 0) {
          Sb = dod + Sb;
        }
        if (LOOK == (YOKO - 1)) {
          Sb = Sb + dod;
        }
      }
      if (LOOK == 0) {
        Sc = dod + Sc;
      }
      if (LOOK == (YOKO)) {
        Sc = Sc + dod;
      }
      if (tate == TATE) {
        Sc = dod + dod + dod;
      }
      char A, B, C, D, E, F, G, H, I;
      A = Sa.at(LOOK);
      B = Sa.at(LOOK + 1);
      C = Sa.at(LOOK + 2);
      D = Sb.at(LOOK);
      E = Sb.at(LOOK + 1);
      F = Sb.at(LOOK + 2);
      G = Sc.at(LOOK);
      H = Sc.at(LOOK + 1);
      I = Sc.at(LOOK + 2);
      if (E == '#') {
        cout << "#";
      } else {
        if (A == '#') {
          sum++;
        }
        if (B == '#') {
          sum++;
        }
        if (C == '#') {
          sum++;
        }
        if (D == '#') {
          sum++;
        }
        if (F == '#') {
          sum++;
        }
        if (G == '#') {
          sum++;
        }
        if (H == '#') {
          sum++;
        }
        if (I == '#') {
          sum++;
        }
        cout << sum;
      }
    }
    Sb = Sa;
    Sc = Sb;
    cout << endl;
  }
}
