#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  string S[H];
  int R[H][W];
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int count;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        count = 0;
        if (S[i - 1][j - 1] == '#') count++;
        if (S[i][j - 1] == '#') count++;
        if (S[i + 1][j - 1] == '#') count++;
        if (S[i - 1][j] == '#') count++;
        if (S[i + 1][j] == '#') count++;
        if (S[i - 1][j + 1] == '#') count++;
        if (S[i][j + 1] == '#') count++;
        if (S[i + 1][j + 1] == '#') count++;
        R[i][j] = count;
      } else {
        R[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (R[i][j] == 0)
        cout << "#";
      else
        cout << R[i][j];
    }
    cout << endl;
  }
}
