#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  int input[H][W];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      input[i][j] = 0;
    }
  }
  char temp;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> temp;
      if (temp == '#') {
        input[i][j] = 9;
        for (int k = -1; k <= 1; ++k) {
          for (int l = -1; l <= 1; ++l) {
            if (i + k < 0 || i + k >= H) continue;
            if (j + l < 0 || j + k >= W) continue;
            ++input[i + k][j + l];
          }
        }
      }
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (input[i][j] >= 9) {
        cout << '#';
      } else {
        cout << input[i][j];
      }
    }
    cout << endl;
  }
}
