#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  int counter = 0;
  cin >> H >> W;
  string S[H];
  for (int a = 0; a < H; a++) {
    cin >> S[a];
  }
  if (H == 1 && W == 1) {
    if (S[0].at(0) == '#')
      cout << "#" << endl;
    else {
      cout << "0" << endl;
    }
  } else if (H == 1 && W != 1) {
    for (int k = 0; k < W; k++) {
      counter = 0;
      if (S[0].at(k) == '#') {
        cout << "#";
        continue;
      } else if (k == 0) {
        if (S[0].at(k + 1) == '#') counter++;
        cout << counter;
        continue;
      } else if (k == W - 1) {
        if (S[0].at(k - 1)) counter++;
        cout << counter << endl;
        continue;
      } else {
        if (S[0].at(k - 1) == '#') counter++;
        if (S[0].at(k + 1) == '#') counter++;
        cout << counter;
        continue;
      }
    }
  } else if (H != 1 && W == 1) {
    for (int n = 0; n < H; n++) {
      counter = 0;
      if (S[H].at(0) == '#') {
        cout << "#" << endl;
        continue;
      } else if (n == 0) {
        if (S[n + 1].at(0) == '#') counter++;
        cout << counter << endl;
        continue;
      } else if (n == H - 1) {
        if (S[n - 1].at(0) == '#') counter++;
        cout << counter << endl;
        continue;
      } else {
        if (S[n - 1].at(0) == '#') counter++;
        if (S[n + 1].at(0) == '#') counter++;
        cout << counter << endl;
        continue;
      }
    }
  } else {
    for (int n = 0; n < H; n++) {
      for (int k = 0; k < W; k++) {
        counter = 0;
        if (S[n].at(k) == '#') {
          if (k == W - 1) {
            cout << "#" << endl;
            continue;
          } else {
            cout << "#";
            continue;
          }
        } else if (n == 0) {
          if (k == 0) {
            if (S[n + 1].at(k) == '#') counter++;
            if (S[n].at(k + 1) == '#') counter++;
            if (S[n + 1].at(k + 1) == '#') counter++;
            cout << counter;
            continue;
          } else if (k == W - 1) {
            if (S[n + 1].at(k) == '#') counter++;
            if (S[n].at(k - 1) == '#') counter++;
            if (S[n + 1].at(k - 1) == '#') counter++;
            cout << counter << endl;
            continue;
          } else {
            if (S[n].at(k - 1) == '#') counter++;
            if (S[n].at(k + 1) == '#') counter++;
            if (S[n + 1].at(k - 1) == '#') counter++;
            if (S[n + 1].at(k) == '#') counter++;
            if (S[n + 1].at(k + 1) == '#') counter++;
            cout << counter;
            continue;
          }
        } else if (n == H - 1) {
          if (k == 0) {
            if (S[n].at(k + 1) == '#') counter++;
            if (S[n - 1].at(k) == '#') counter++;
            if (S[n - 1].at(k + 1) == '#') counter++;
            cout << counter;
            continue;
          } else if (k == W - 1) {
            if (S[n].at(k - 1) == '#') counter++;
            if (S[n - 1].at(k) == '#') counter++;
            if (S[n - 1].at(k - 1) == '#') counter++;
            cout << counter << endl;
            continue;
          } else {
            if (S[n].at(k - 1) == '#') counter++;
            if (S[n].at(k + 1) == '#') counter++;
            if (S[n - 1].at(k - 1) == '#') counter++;
            if (S[n - 1].at(k) == '#') counter++;
            if (S[n - 1].at(k + 1) == '#') counter++;
            cout << counter;
            continue;
          }
        } else {
          if (k == 0) {
            if (S[n - 1].at(k) == '#') counter++;
            if (S[n].at(k + 1) == '#') counter++;
            if (S[n + 1].at(k + 1) == '#') counter++;
            if (S[n + 1].at(k) == '#') counter++;
            if (S[n + 1].at(k + 1) == '#') counter++;
            cout << counter;
            continue;
          } else if (k == W - 1) {
            if (S[n - 1].at(k) == '#') counter++;
            if (S[n].at(k - 1) == '#') counter++;
            if (S[n - 1].at(k - 1) == '#') counter++;
            if (S[n + 1].at(k) == '#') counter++;
            if (S[n + 1].at(k - 1) == '#') counter++;
            cout << counter << endl;
            continue;
          } else {
            if (S[n - 1].at(k - 1) == '#') counter++;
            if (S[n - 1].at(k) == '#') counter++;
            if (S[n - 1].at(k + 1) == '#') counter++;
            if (S[n].at(k - 1) == '#') counter++;
            if (S[n].at(k + 1) == '#') counter++;
            if (S[n + 1].at(k + 1) == '#') counter++;
            if (S[n + 1].at(k) == '#') counter++;
            if (S[n + 1].at(k - 1) == '#') counter++;
            cout << counter;
            continue;
          }
        }
      }
    }
  }
}
