#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  char S[53][53];
  cin >> H >> W;
  for (int j = 0; j < W + 2; ++j) {
    S[0][j] = ' ';
  }
  for (int i = 1; i < H + 1; ++i) {
    S[i][0] = ' ';
    cin >> S[i];
    S[i][W + 1] = ' ';
  }
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      int count = 0;
      if (S[i][j] == '#') {
        continue;
      }
      for (int k = 0; k < 3; ++k) {
        for (int l = 0; l < 3; ++l) {
          if (S[i - 1 + k][j - 1 + l] == '#') {
            ++count;
          }
        }
      }
      S[i][j] = to_string(count).c_str()[0];
    }
    cout << S[i];
  }
  return 0;
}
