#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, counter;
  string INPUT, temp = "";
  cin >> H >> W;
  for (int i = 0; i <= H; i++) {
    getline(cin, temp);
    INPUT += temp;
  }
  for (int i = 0; i < H * W; i++) {
    counter = 0;
    if (INPUT.at(i) == '#') {
      cout << "#";
    } else if (i == 0) {
      if (INPUT.at(i + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W) == '#') {
        counter++;
      }
      if (INPUT.at(i + W + 1) == '#') {
        counter++;
      }
      cout << counter;
    } else if (i > 0 && i < W - 1) {
      if (INPUT.at(i - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W) == '#') {
        counter++;
      }
      if (INPUT.at(i + W + 1) == '#') {
        counter++;
      }
      cout << counter;
    } else if (i == W - 1) {
      if (INPUT.at(i - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W) == '#') {
        counter++;
      }
      if (INPUT.at(i + W - 1) == '#') {
        counter++;
      }
      cout << counter;
    } else if (i == (H - 1) * W) {
      if (INPUT.at(i - W) == '#') {
        counter++;
      }
      if (INPUT.at(i - W + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + 1) == '#') {
        counter++;
      }
      cout << counter;
    } else if (i == H * W - 1) {
      if (INPUT.at(i - W - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i - W) == '#') {
        counter++;
      }
      if (INPUT.at(i - 1) == '#') {
        counter++;
      }
      cout << counter;
    } else if ((i + 1) % W == 0) {
      if (INPUT.at(i - W - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i - W) == '#') {
        counter++;
      }
      if (INPUT.at(i - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W) == '#') {
        counter++;
      }
      cout << counter;
    } else if (i > (H - 1) * W) {
      if (INPUT.at(i - W - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i - W) == '#') {
        counter++;
      }
      if (INPUT.at(i - W + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + 1) == '#') {
        counter++;
      }
      cout << counter;
    } else if (i % W == 0) {
      if (INPUT.at(i - W) == '#') {
        counter++;
      }
      if (INPUT.at(i - W + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W) == '#') {
        counter++;
      }
      if (INPUT.at(i + W + 1) == '#') {
        counter++;
      }
      cout << counter;
    } else {
      if (INPUT.at(i - W - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i - W) == '#') {
        counter++;
      }
      if (INPUT.at(i - W + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W - 1) == '#') {
        counter++;
      }
      if (INPUT.at(i + W) == '#') {
        counter++;
      }
      if (INPUT.at(i + W + 1) == '#') {
        counter++;
      }
      cout << counter;
    }
    if ((i + 1) % W == 0) {
      cout << endl;
    }
  }
}
