#include <bits/stdc++.h>
using namespace std;
int main() {
  int W, H;
  char r;
  scanf("%d%d", &W, &H);
  int board[H][W];
  char ans[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf(" %c", &r);
      if (r == '#') {
        board[i][j] = -10;
        for (int k = 0; k < 3; k++) {
          for (int l = 0; l < 3; l++) {
            board[i + k - 1][j + l - 1]++;
          }
        }
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < 3; j++) {
      if (board[i][j] < 0) {
        ans[i][j] = '#';
      } else {
        ans[i][j] += '0';
      }
      printf(" %c\n", ans[i][j]);
    }
  }
}
