#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string a, b, c;
  string nulll;
  for (int i = 0; i < 52; i++) nulll += ".";
  for (int i = 1; i <= H; i++) {
    if (H == 1) {
      a = nulll;
      cin >> b;
      b = "." + b + ".";
      c = nulll;
    } else {
      if (i == 1) {
        a = nulll;
        cin >> b >> c;
        b = "." + b + ".";
        c = "." + c + ".";
      } else if (i == H) {
        a = b;
        b = c;
        c = nulll;
      } else {
        a = b;
        b = c;
        cin >> c;
        c = "." + c + ".";
      }
    }
    for (int j = 1; j <= W; j++) {
      char x = b.at(j);
      if (x == '.') {
        int counter = 0;
        if (a.at(j - 1) == '#') counter++;
        if (a.at(j) == '#') counter++;
        if (a.at(j + 1) == '#') counter++;
        if (b.at(j - 1) == '#') counter++;
        if (b.at(j + 1) == '#') counter++;
        if (c.at(j - 1) == '#') counter++;
        if (c.at(j) == '#') counter++;
        if (c.at(j + 1) == '#') counter++;
        char y;
        y = '0' + counter;
        b.at(j) = y;
      }
    }
    string d = b.erase(0, 1);
    string e = d.erase(W, 1);
    cout << e << endl;
  }
}
