#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  char c;
  string S_up, S_cen, S_down, S;
  cin >> H >> W >> S_cen >> S_down;
  S = "";
  if (S_cen.at(0) == '#')
    c = '#';
  else {
    c = '0';
    if (S_cen.at(1) == '#') c++;
    if (S_down.at(0) == '#') c++;
    if (S_down.at(1) == '#') c++;
  }
  S += c;
  for (int j = 1; j < W - 1; j++) {
    if (S_cen.at(j) == '#')
      c = '#';
    else {
      c = '0';
      if (S_cen.at(j - 1) == '#') c++;
      if (S_cen.at(j + 1) == '#') c++;
      if (S_down.at(j - 1) == '#') c++;
      if (S_down.at(j) == '#') c++;
      if (S_down.at(j + 1) == '#') c++;
    }
    S += c;
  }
  if (S_cen.at(W - 1) == '#')
    c = '#';
  else {
    c = '0';
    if (S_cen.at(W - 2) == '#') c++;
    if (S_down.at(W - 2) == '#') c++;
    if (S_down.at(W - 1) == '#') c++;
  }
  S += c;
  cout << S << endl;
  for (int i = 1; i < H - 1; i++) {
    S_up = S_cen;
    S_cen = S_down;
    cin >> S_down;
    S = "";
    if (S_cen.at(0) == '#')
      c = '#';
    else {
      c = '0';
      if (S_up.at(0) == '#') c++;
      if (S_up.at(1) == '#') c++;
      if (S_cen.at(1) == '#') c++;
      if (S_down.at(0) == '#') c++;
      if (S_down.at(1) == '#') c++;
    }
    S += c;
    for (int j = 1; j < W - 1; j++) {
      if (S_cen.at(j) == '#')
        c = '#';
      else {
        c = '0';
        if (S_up.at(j - 1) == '#') c++;
        if (S_up.at(j) == '#') c++;
        if (S_up.at(j + 1) == '#') c++;
        if (S_cen.at(j - 1) == '#') c++;
        if (S_cen.at(j + 1) == '#') c++;
        if (S_down.at(j - 1) == '#') c++;
        if (S_down.at(j) == '#') c++;
        if (S_down.at(j + 1) == '#') c++;
      }
      S += c;
    }
    if (S_cen.at(W - 1) == '#')
      c = '#';
    else {
      c = '0';
      if (S_up.at(W - 2) == '#') c++;
      if (S_up.at(W - 1) == '#') c++;
      if (S_cen.at(W - 2) == '#') c++;
      if (S_down.at(W - 2) == '#') c++;
      if (S_down.at(W - 1) == '#') c++;
    }
    S += c;
    cout << S << endl;
  }
  S_up = S_cen;
  S_cen = S_down;
  S = "";
  if (S_cen.at(0) == '#')
    c = '#';
  else {
    c = '0';
    if (S_cen.at(1) == '#') c++;
    if (S_up.at(0) == '#') c++;
    if (S_up.at(1) == '#') c++;
  }
  S += c;
  for (int j = 1; j < W - 1; j++) {
    if (S_cen.at(j) == '#')
      c = '#';
    else {
      c = '0';
      if (S_cen.at(j - 1) == '#') c++;
      if (S_cen.at(j + 1) == '#') c++;
      if (S_up.at(j - 1) == '#') c++;
      if (S_up.at(j) == '#') c++;
      if (S_up.at(j + 1) == '#') c++;
    }
    S += c;
  }
  if (S_cen.at(W - 1) == '#')
    c = '#';
  else {
    c = '0';
    if (S_cen.at(W - 2) == '#') c++;
    if (S_up.at(W - 2) == '#') c++;
    if (S_up.at(W - 1) == '#') c++;
  }
  S += c;
  cout << S << endl;
}
