#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<string>> s(h, vector<string>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int ans = 0;
      if (s[i][j] == ".") {
        for (int k = -1; k <= 1; k++) {
          for (int l = -1; l <= 1; l++) {
            if (i + k >= 0 && j + l >= 0) {
              if (s[i + k][j + l] == "#") ans++;
            }
          }
        }
        s[i][j] = to_string(ans);
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j == w - 1)
        cout << s[i][j] << endl;
      else
        cout << s[i][j];
    }
  }
}
