#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> board(H);
  int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  for (int i = 0; i < H; i++) {
    cin >> board.at(i);
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (board.at(i).at(j) == '#') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        if (i + dy[k] < 0 || i + dy[k] >= H) continue;
        if (j + dx[k] < 0 || j + dx[k] >= W) continue;
        if (board.at(i + dy[k]).at(j + dx[k]) == '#') {
          cnt++;
        }
      }
      board.at(i).at(j) = (cnt == 0 ? '#' : cnt);
    }
  }
  for (int i = 0; i < H; i++) cout << board.at(i) << endl;
}
