import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 读取矩阵的行数和列数
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        scanner.nextLine(); // 消耗换行符

        // 读取初始扫雷矩阵
        char[][] matrix = new char[n][m];
        for (int i = 0; i < n; i++) {
            String line = scanner.nextLine();
            matrix[i] = line.toCharArray();
        }

        // 计算并输出完整的扫雷矩阵
        for (int i = 0; i < n; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == '*') {
                    // 如果是雷,直接添加'*'
                    sb.append('*');
                } else {
                    // 计算周围8个方向的雷数量
                    int count = countMines(matrix, i, j, n, m);
                    sb.append(count);
                }
            }
            System.out.println(sb.toString());
        }
    }

    // 计算指定位置周围8个方向的雷数量
    private static int countMines(char[][] matrix, int x, int y, int n, int m) {
        int count = 0;
        // 8个方向的偏移量
        int[][] directions = {
            {-1, -1}, {-1, 0}, {-1, 1},
            {0, -1},          {0, 1},
            {1, -1},  {1, 0}, {1, 1}
        };

        // 检查每个方向
        for (int[] dir : directions) {
            int nx = x + dir[0];
            int ny = y + dir[1];

            // 确保坐标在矩阵范围内
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                if (matrix[nx][ny] == '*') {
                    count++;
                }
            }
        }
        return count;
    }
}