H,W = map(int,input().split())

A = [list(input()) for i in range(H)]

for i in range(H):
	for j in range(W):
		if A[i][j] != '#':
			count = 0
			for k in range(-1,2):
				for l in range(-1,2):
					if -1 < i + k and i + k < H and -1 < j + l and j + l < W:
						if A[i+k][j+l] == '#':
							count += 1
			
			A[i][j] = str(count)

for i in A:
	print(''.join(i))