import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			String map[][] = new String[H][W];

			String S;
			for (int i = 0; i < H; i++) {
				S = sc.next();
				for (int j = 0; j < W; j++) {
					map[i][j] = ".";
					if (S.charAt(j) == '#') {
						map[i][j] = "#";
					}
				}
			}

			int count;
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < H; i++) {
				sb.setLength(0);
				for (int j = 0; j < W; j++) {
					if (map[i][j].equals(".")) {
						count = 0;
						if (i - 1 >= 0 && j - 1 >= 0 && map[i - 1][j - 1].equals("#")) {
							count++;
						}
						if (i - 1 >= 0 && map[i - 1][j].equals("#")) {
							count++;
						}
						if (i - 1 >= 0 && j + 1 < W && map[i - 1][j + 1].equals("#")) {
							count++;
						}
						if (j - 1 >= 0 && map[i][j - 1].equals("#")) {
							count++;
						}
						if (j + 1 < W && map[i][j + 1].equals("#")) {
							count++;
						}
						if (i + 1 < H && j - 1 >= 0 && map[i + 1][j - 1].equals("#")) {
							count++;
						}
						if (i + 1 < H && map[i + 1][j].equals("#")) {
							count++;
						}
						if (i + 1 < H && j + 1 < W && map[i + 1][j + 1].equals("#")) {
							count++;
						}
						sb.append(count);
					}else{
						sb.append("#");
					}
				}
				System.out.println(sb);
			}
		}
	}
}