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