#include<stdio.h>
#include<stdlib.h>
int main(void) {
	int h, w;
	scanf("%d %d", &h, &w);
	int i, j;
	char** a = malloc(sizeof(char*) * h);
	for (i = 0; i < h; i++) {
		a[i] = malloc(sizeof(char) * w);
	}
	for (i = 0; i < h; i++)
		scanf("%s", a[i]);
	int x[8] = { 1,1,1,0,-1,-1,-1,0 };
	int y[8] = { -1,0,1,1,1,0,-1,-1 };
	int k, count = 0;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (a[i][j] == '.') {
				count = 0;
				for (k = 0; k < 8; k++) {
					if (a[x[k]][y[k]] == '#')
						count++;
				}
				a[i][j] = '0' + count;
			}
		}
	}
	for (i = 0; i < h; i++) {
		printf("%s\n", a[i]);
	}
	return 0;
}