import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int H = scanner.nextInt();
        int W = scanner.nextInt();

        int[][] map = new int[H + 2][W + 2];

        for (int i = 0; i < H; i++) {
            String str = scanner.next();
            for (int j = 0; j < W; j++) {
                String word = str.substring(j, j + 1);
                if (word.equals("#")) {
                    map[i + 1][j + 1] = -100;
                    for (int k = 0; k < 3; k++) {
                        for (int l = 0; l < 3; l++) {
                            map[i + k][j + l]++;
                        }
                    }
                }
            }
        }

//        for (int i = 0; i < H + 2; i++) {
//            for (int j = 0; j < W + 2; j++) {
//                System.out.print(map[i][j]);
//            }
//            System.out.println();
//        }

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (map[i + 1][j + 1] < 0) {
                    System.out.print("#");
                } else {
                    System.out.print(map[i + 1][j + 1]);
                }
            }
            System.out.println();
        }
    }
}