#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    string S;
    cin >> S;
    for (int j = 0; j < W; j++) {
      data.at(i).at(j) = S.at(j);
    }
  }
  for (int i = 0; i < H; i++) {
    string str = "";
    for (int j = 0; j < W; j++) {
      char c = data.at(i).at(j);
      if (c == '#') {
        str += '#';
      } else {
        int n = 0;
        for (int k = 0; k < 3; k++) {
          for (int l = 0; l < 3; l++) {
            if (l == 1) {
              continue;
            }
            if (i == 0) {
              if (k == 0) {
                continue;
              }
            } else if (i == H - 1) {
              if (k == 2) {
                continue;
              }
            } else {
              n++;
            }
          }
        }
        char *s;
        sprintf(s, "%d", n);
        str += s;
      }
      cout << str << endl;
    }
  }
}
