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