#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, tmp;
  cin >> H >> W;
  string s[50][50], a[50][50], ans;
  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      cin >> s[i][k];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      tmp = 0;
      ans = ".";
      if (i == 0 && k == 0) {
        if (s[i][k] == "#") ans = "#";
        if (s[i][k + 1] == "#") tmp++;
        if (s[i + 1][k + 1] == "#") tmp++;
        if (s[i + 1][k] == "#") tmp++;
      } else if (i == H - 1 && k == 0) {
        if (s[i][k] == "#") ans = "#";
        if (s[i - 1][k] == "#") tmp++;
        if (s[i][k + 1] == "#") tmp++;
        if (s[i - 1][k + 1] == "#") tmp++;
      } else if (i == H - 1 && k == W - 1) {
        if (s[i][k] == "#") ans = "#";
        if (s[i][k - 1] == "#") tmp++;
        if (s[i - 1][k] == "#") tmp++;
        if (s[i - 1][k - 1] == "#") tmp++;
      } else if (i == 0 && k == W - 1) {
        if (s[i][k] == "#") ans = "#";
        if (s[i][k - 1] == "#") tmp++;
        if (s[i + 1][k] == "#") tmp++;
        if (s[i + 1][k - 1] == "#") tmp++;
      } else if (i == 0) {
        if (s[i][k] == "#") ans = "#";
        if (s[i][k - 1] == "#") tmp++;
        if (s[i][k + 1] == "#") tmp++;
        if (s[i + 1][k - 1] == "#") tmp++;
        if (s[i + 1][k] == "#") tmp++;
        if (s[i + 1][k + 1] == "#") tmp++;
      } else if (k == 0) {
        if (s[i][k] == "#") ans = "#";
        if (s[i - 1][k] == "#") tmp++;
        if (s[i - 1][k + 1] == "#") tmp++;
        if (s[i][k + 1] == "#") tmp++;
        if (s[i + 1][k + 1] == "#") tmp++;
        if (s[i + 1][k] == "#") tmp++;
      } else if (k == W - 1) {
        if (s[i][k] == "#") ans = "#";
        if (s[i - 1][k] == "#") tmp++;
        if (s[i - 1][k - 1] == "#") tmp++;
        if (s[i][k - 1] == "#") tmp++;
        if (s[i + 1][k - 1] == "#") tmp++;
        if (s[i + 1][k] == "#") tmp++;
      } else if (i == H - 1) {
        if (s[i][k] == "#") ans = "#";
        if (s[i][k - 1] == "#") tmp++;
        if (s[i - 1][k - 1] == "#") tmp++;
        if (s[i - 1][k] == "#") tmp++;
        if (s[i - 1][k + 1] == "#") tmp++;
        if (s[i][k + 1] == "#") tmp++;
      } else {
        if (s[i][k] == "#") ans = "#";
        if (s[i - 1][k - 1] == "#") tmp++;
        if (s[i - 1][k] == "#") tmp++;
        if (s[i - 1][k + 1] == "#") tmp++;
        if (s[i][k - 1] == "#") tmp++;
        if (s[i][k + 1] == "#") tmp++;
        if (s[i + 1][k - 1] == "#") tmp++;
        if (s[i + 1][k] == "#") tmp++;
        if (s[i + 1][k + 1] == "#") tmp++;
      }
      if (ans == "#") {
        a[i][k] = "#";
      } else {
        a[i][k] = to_string(tmp);
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int k = 0; k < W; k++) {
      cout << a[i][k];
    }
    cout << endl;
  }
  return 0;
}
