#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  vector<string> s(51);
  vector<int> x = {1, 1, 1, 0, 0, -1, -1, -1};
  vector<int> y = {1, 0, -1, 1, -1, 1, 0, -1};
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s.at(i);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int ni, nj, ans;
      if (s[i][j] == '#') continue;
      for (int k = 0; k < 8; k++) {
        ni = i + x[k];
        nj = j + y[k];
        if (ni < 0 || h <= ni) continue;
        if (nj < 0 || w <= nj) continue;
        if (s[ni][nj] == '#') ans++;
      }
      s[i][j] = char(ans);
    }
    cout << s[i] << endl;
  }
}
