#include <bits/stdc++.h>
using namespace std;
int flag(int h, int w, int H, int W) {
  int fhw, fh, fw;
  if (h == 0) {
    fh = 10;
  } else if (h != 0 && h != H - 1) {
    fh = 20;
  } else {
    fh = 30;
  }
  if (w == 0) {
    fw = 1;
  } else if (w != 0 && w != W - 1) {
    fh = 2;
  } else {
    fh = 3;
  }
  fhw = fh + fw;
  return fhw;
}
int main() {
  int H, W;
  cin >> H >> W;
  char ist[55][55];
  char ost[55][55];
  for (int h = 0; h < H; h++) {
    cin.getline(ist[h], 55);
  }
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (ist[h][w] != '#') {
        int fl = flag(h, w, H, W);
        int bomb = 0;
        switch (fl) {
          case 11:
            if (ist[h + 1][w] != '#') bomb++;
            if (ist[h][w + 1] != '#') bomb++;
            if (ist[h + 1][w + 1] != '#') bomb++;
            break;
          case 12:
            if (ist[h][w - 1] != '#') bomb++;
            if (ist[h][w + 1] != '#') bomb++;
            if (ist[h + 1][w - 1] != '#') bomb++;
            if (ist[h + 1][w] != '#') bomb++;
            if (ist[h + 1][w + 1] != '#') bomb++;
            break;
          case 13:
            if (ist[h][w - 1] != '#') bomb++;
            if (ist[h - 1][w - 1] != '#') bomb++;
            if (ist[h - 1][w] != '#') bomb++;
            break;
          case 21:
            if (ist[h - 1][w] != '#') bomb++;
            if (ist[h + 1][w] != '#') bomb++;
            if (ist[h - 1][w + 1] != '#') bomb++;
            if (ist[h][w + 1] != '#') bomb++;
            if (ist[h - 1][w + 1] != '#') bomb++;
            break;
          case 22:
            if (ist[h - 1][w - 1] != '#') bomb++;
            if (ist[h - 1][w] != '#') bomb++;
            if (ist[h - 1][w + 1] != '#') bomb++;
            if (ist[h][w - 1] != '#') bomb++;
            if (ist[h][w + 1] != '#') bomb++;
            if (ist[h + 1][w - 1] != '#') bomb++;
            if (ist[h + 1][w] != '#') bomb++;
            if (ist[h + 1][w + 1] != '#') bomb++;
            break;
          case 23:
            if (ist[h - 1][w - 1] != '#') bomb++;
            if (ist[h - 1][w] != '#') bomb++;
            if (ist[h][w - 1] != '#') bomb++;
            if (ist[h + 1][w - 1] != '#') bomb++;
            if (ist[h + 1][w] != '#') bomb++;
            break;
          case 31:
            if (ist[h - 1][w] != '#') bomb++;
            if (ist[h - 1][w + 1] != '#') bomb++;
            if (ist[h][w + 1] != '#') bomb++;
            break;
          case 32:
            if (ist[h - 1][w - 1] != '#') bomb++;
            if (ist[h - 1][w] != '#') bomb++;
            if (ist[h - 1][w + 1] != '#') bomb++;
            if (ist[h][w - 1] != '#') bomb++;
            if (ist[h][w + 1] != '#') bomb++;
            break;
          case 33:
            if (ist[h - 1][w - 1] != '#') bomb++;
            if (ist[h - 1][w] != '#') bomb++;
            if (ist[h][w - 1] != '#') bomb++;
            break;
            ost[h][w] = char('0' + bomb);
        }
      } else {
        ost[h][w] = '#';
      }
    }
  }
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      cout << ost[h][w];
    }
    cout << endl;
  }
  return 0;
}
