#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, i, j;
  int count = 0;
  string S[50];
  const int di[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  const int dj[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int ki, kj;
  cin >> 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] == '#') continue;
      count = 0;
      for (int d = 0; d < 8; d++) {
        ki = i + di[d];
        kj = j + dj[d];
        if (ki < 0 || ki > H) continue;
        if (kj < 0 || kj > W) continue;
        if (S[ki][kj] == '#') count++;
      }
      S[i][j] = char(count + '0');
    }
  }
  for (i = 0; i < H; i++) cout << S[i] << endl;
}
