#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int x, y;
  cin >> x >> y;
  a = "0";
  for (int i = 1; i < y + 2; i++) a += "0";
  for (int i = 0; i < x; i++) {
    cin >> b;
    for (int j = 0; j < y; j++) {
      if (b.at(j) == '.') b.at(j) = '0';
    }
    a += "0" + b + "0";
  }
  for (int i = 0; i < y + 2; i++) a += "0";
  for (int i = y + 3; i < (x + 1) * (y + 1); i++) {
    if (a.at(i) == '0') {
      int count = 0;
      if (a.at(i + 1) == '#') count++;
      if (a.at(i + y + 1) == '#') count++;
      if (a.at(i + y + 2) == '#') count++;
      if (a.at(i + y + 3) == '#') count++;
      if (a.at(i - 1) == '#') count++;
      if (a.at(i - y - 1) == '#') count++;
      if (a.at(i - y - 2) == '#') count++;
      if (a.at(i - y - 3) == '#') count++;
      a.at(i) = count;
    }
  }
  for (int i = 2; i < x + 1; i++) {
    for (int j = (i - 1) * (y + 2) + 1; j < i * (y + 2) - 1; j++)
      cout << a.at(j);
    cout << endl;
  }
}
