#include <iostream>
#include <cstdio>
using namespace std;
char s[55];
int n, m;	bool map[55][55];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", s);
		for (int j = 1; j <= m; j++)
			map[i][j] = (s[j-1] == '#');
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			if (map[i][j])	printf("#");
			else	printf("%d", map[i-1][j]+map[i][j-1]+map[i][j+1]+map[i+1][j]+map[i-1][j-1]+map[i+1][j+1]+map[i-1][j+1]+map[i+1][j-1]);
		printf("\n");
	}
	return 0;
}
