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