#include <bits/stdc++.h>
using namespace std;
int main() {
  string num = "012345678";
  int H, W;
  cin >> H >> W;
  vector<string> Mine(H, "");
  for (int i = 0; i < H; i++) {
    cin >> Mine.at(i);
  }
  for (int i = 0; i < H; i++) {
    string up, middle, down;
    char UpLeft, UpCenter, UpRight;
    char MiddleLeft, MiddleCenter, MiddleRight;
    char DownLeft, DownCenter, DownRight;
    if (i == 0) {
      up = Mine.at(0);
      for (int k = 0; k < W; k++) {
        up.at(k) = '.';
      }
      middle = Mine.at(i);
      down = Mine.at(i + 1);
    } else if (i == (H - 1)) {
      up = Mine.at(i - 1);
      middle = Mine.at(i);
      down = Mine.at(H - 1);
      for (int k = 0; k < W; k++) {
        down.at(k) = '.';
      }
    } else {
      up = Mine.at(i - 1);
      middle = Mine.at(i);
      down = Mine.at(i + 1);
    }
    for (int j = 0; j < W; j++) {
      if (j == 0) {
        UpLeft = '.';
        UpCenter = up.at(j);
        UpRight = up.at(j + 1);
        MiddleLeft = '.';
        MiddleCenter = middle.at(j);
        MiddleRight = middle.at(j + 1);
        DownLeft = '.';
        DownCenter = down.at(j);
        DownRight = down.at(j + 1);
      } else if (j == (W - 1)) {
        UpLeft = up.at(j - 1);
        UpCenter = up.at(j);
        UpRight = '.';
        MiddleLeft = middle.at(j - 1);
        MiddleCenter = middle.at(j);
        MiddleRight = '.';
        DownLeft = down.at(j - 1);
        DownCenter = down.at(j);
        DownRight = '.';
      } else {
        UpLeft = up.at(j - 1);
        UpCenter = up.at(j);
        UpRight = up.at(j + 1);
        MiddleLeft = middle.at(j - 1);
        MiddleCenter = middle.at(j);
        MiddleRight = middle.at(j + 1);
        DownLeft = down.at(j - 1);
        DownCenter = down.at(j);
        DownRight = down.at(j + 1);
      }
      int N = 0;
      if (UpLeft == '#') {
        N += 1;
      }
      if (UpCenter == '#') {
        N += 1;
      }
      if (UpRight == '#') {
        N += 1;
      }
      if (MiddleLeft == '#') {
        N += 1;
      }
      if (MiddleRight == '#') {
        N += 1;
      }
      if (DownLeft == '#') {
        N += 1;
      }
      if (DownCenter == '#') {
        N += 1;
      }
      if (DownRight == '#') {
        N += 1;
      }
      if (MiddleCenter != '#') {
        middle.at(j) = num.at(N);
      }
    }
    cout << middle << endl;
  }
}
