#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string S0, S1;
  cin >> S0;
  if (H > 1) cin >> S1;
  for (int j = 0; j < W; j++) {
    if (S0.at(j) == '.') {
      int count = 0;
      char countre;
      if (S0.at(j - 1) == '#' && j > 0) count++;
      if (S0.at(j + 1) == '#' && j < W - 1) count++;
      if (H > 1) {
        if (S1.at(j - 1) == '#' && j > 0) count++;
        if (S1.at(j) == '#') count++;
        if (S1.at(j + 1) == '#' && j < W - 1) count++;
      }
      countre = (char)count;
      S0.at(j) = countre;
    }
  }
  cout << S0 << endl;
  if (H > 1) {
    string Sb, Sn, Sa;
    Sb = S0;
    Sn = S1;
    if (H > 2) cin >> Sa;
    for (int i = 0; i < H - 1; i++) {
      for (int j = 0; j < W; j++) {
        if (Sn.at(j) == '.') {
          int count = 0;
          char countre;
          if (Sb.at(j - 1) == '#' && j > 0) count++;
          if (Sb.at(j) == '#') count++;
          if (Sb.at(j + 1) == '#' && j < W - 1) count++;
          if (Sn.at(j - 1) == '#' && j > 0) count++;
          if (Sn.at(j + 1) == '#' && j < W - 1) count++;
          if (i > 0) {
            if (Sa.at(j - 1) == '#' && j > 0) count++;
            if (Sa.at(j) == '#') count++;
            if (Sa.at(j + 1) == '#' && j < W - 1) count++;
          }
          countre = (char)count;
          Sn.at(j) = countre;
        }
      }
      cout << Sn << endl;
      Sb = Sn;
      if (H > 2) Sn = Sa;
      string S;
      if (i < H - 2) {
        cin >> S;
        Sa = S;
      }
    }
  }
}
