#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  string m, s, s2;
  cin >> h >> w;
  for (int i = 0; i < w; i++) m += '.';
  cin >> s;
  for (int i = 0; i < h; i++) {
    cin >> s2;
    for (int j = 0; j < w; j++) {
      int c = 0;
      char cc;
      if (j != 0 && m.at(j - 1) == '#') c += 1;
      if (m.at(j) == '#') c += 1;
      if (j != w - 1 && m.at(j + 1) == '#') c += 1;
      if (j != 0 && s.at(j - 1) == '#') c += 1;
      if (j != w - 1 && s.at(j + 1) == '#') c += 1;
      if (j != 0 && s2.at(j - 1) == '#') c += 1;
      if (s2.at(j) == '#') c += 1;
      if (j != w - 1 && s2.at(j + 1) == '#') c += 1;
      if (s.at(j) == '#')
        cout << '#';
      else
        cout << c;
    }
    m = s;
    s = s2;
    cout << endl;
  }
}
