#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, count;
  string s1, s2, s3;
  cin >> H >> W;
  cin >> s1 >> s2 >> s3;
  for (int i = 0; i < H; i++) {
    if (i == 0) {
      for (int j = 0; j < W; j++) {
        count = 0;
        if (j == 0) {
          if (s1.at(j) == '.') {
            if (s1.at(j + 1) == '#') count++;
            if (s2.at(j) == '#') count++;
            if (s2.at(j + 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        } else if (0 < j < W - 1) {
          if (s1.at(j) == '.') {
            if (s1.at(j - 1) == '#') count++;
            if (s1.at(j + 1) == '#') count++;
            if (s2.at(j) == '#') count++;
            if (s2.at(j - 1) == '#') count++;
            if (s2.at(j + 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        } else {
          if (s1.at(j) == '.') {
            if (s1.at(j - 1) == '#') count++;
            if (s2.at(j) == '#') count++;
            if (s2.at(j - 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        }
      }
    } else if (0 < i < H - 1) {
      for (int j = 0; j < W; j++) {
        count = 0;
        if (j == 0) {
          if (s2.at(j) == '.') {
            if (s1.at(j) == '#') count++;
            if (s1.at(j + 1) == '#') count++;
            if (s2.at(j + 1) == '#') count++;
            if (s3.at(j) == '#') count++;
            if (s3.at(j + 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        } else if (0 < j < W - 1) {
          if (s2.at(j) == '.') {
            if (s1.at(j) == '#') count++;
            if (s1.at(j - 1) == '#') count++;
            if (s1.at(j + 1) == '#') count++;
            if (s2.at(j - 1) == '#') count++;
            if (s2.at(j + 1) == '#') count++;
            if (s3.at(j) == '#') count++;
            if (s3.at(j - 1) == '#') count++;
            if (s3.at(j + 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        } else {
          if (s2.at(j) == '.') {
            if (s1.at(j) == '#') count++;
            if (s1.at(j - 1) == '#') count++;
            if (s2.at(j - 1) == '#') count++;
            if (s3.at(j) == '#') count++;
            if (s3.at(j - 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        }
      }
      if (i != H - 2) {
        s1 = s2;
        s2 = s3;
        cin >> s3;
      }
    } else {
      for (int j = 0; j < W; j++) {
        count = 0;
        if (j == 0) {
          if (s3.at(j) == '.') {
            if (s3.at(j + 1) == '#') count++;
            if (s2.at(j) == '#') count++;
            if (s2.at(j + 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        } else if (0 < j < W - 1) {
          if (s3.at(j) == '.') {
            if (s3.at(j - 1) == '#') count++;
            if (s3.at(j + 1) == '#') count++;
            if (s2.at(j) == '#') count++;
            if (s2.at(j - 1) == '#') count++;
            if (s2.at(j + 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        } else {
          if (s1.at(j) == '.') {
            if (s3.at(j - 1) == '#') count++;
            if (s2.at(j) == '#') count++;
            if (s2.at(j - 1) == '#') count++;
            cout << count;
          } else {
            cout << '#';
          }
        }
      }
    }
    cout << endl;
  }
}
