#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string S[60];
  for (int i = 1; i < H + 1; i++) {
    cin >> S[i];
    S[i] = "." + S[i] + ".";
  }
  S[0] = S[H + 1] = "Null";
  int M[60][60];
  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      if ((S[i])[j] == '#')
        M[i][j] = 1;
      else
        M[i][j] = 0;
    }
  }
  int L[60][60];
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      if (M[i][j] == 0) {
        L[i][j] = M[i][j - 1] + M[i][j + 1] + M[i - 1][j - 1] + M[i - 1][j] +
                  M[i - 1][j + 1] + M[i + 1][j - 1] + M[i + 1][j] +
                  M[i + 1][j + 1];
      }
    }
  }
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      if ((S[i])[j] == '#')
        cout << (S[i])[j];
      else
        cout << L[i][j];
      if (j == W) cout << endl;
    }
  }
  return 0;
}
