/* BC142 扫雷 */
#include <stdio.h>
#include <string.h>
#define MAXSIZE 1002

int main() {
    int n = 0, m = 0;
    char mine[MAXSIZE][MAXSIZE];
	int nums[MAXSIZE][MAXSIZE];
    int X_axis[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
    int Y_axis[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };

    memset(mine, '.', sizeof(mine));      // 初始化
    memset(nums, 0, sizeof(nums));

    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {             // 输入
	  
        char tmp = getchar();
	  // 最关键的一步,使用getcahr()还不行,还得用一个临时变量吸收\n, 否则\n会污染数组
	  
        for (int j = 1; j <= m; j++) {
            scanf("%c", &mine[i][j]);
        }
    }

    // 统计雷个数
    for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
            if(mine[i][j] == '*')
                for(int k = 0; k < 8; k++)
                    nums[(X_axis[k] + i)][(Y_axis[k] + j)] += 1;
        }
    }

    // 输出数字矩阵
    for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
            if(mine[i][j] == '*')
                printf("*");
            else
                printf("%d", nums[i][j]);
        }
        printf("\n");
    }
    return 0;
}