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