#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < W; ++i) cin >> S[i];
  int ans;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j] == '#') continue;
      ans = 0;
      for (int k = i - 1; k <= i + 1; ++k) {
        for (int l = j - 1; l <= j + 1; ++l) {
          if (S[k][l] == '#') ans++;
        }
      }
      S[i][j] = '0' + ans;
    }
  }
  for (int i = 0; i < H; ++i) cout << S[i] << endl;
}
