#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string board[50];
  for (int i = 0; i < H; i++) cin >> board[i];
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (board[i][j] == '#') continue;
      int total = 0;
      for (int d = 0; d < 8; d++) {
        const int nextX = dx[d] + j;
        const int nextY = dy[d] + i;
        if (nextX >= 0 && W >= nextX && nextY >= 0 && H >= nextY &&
            board[nextY][nextX] == '#')
          total++;
      }
      board[i][j] = '0' + total;
    }
  }
  for (int i = 0; i < H; i++) cout << board[i] << endl;
}
