H, W = map(int, raw_input().split())
field = []
for i in range(0, H):
	lst = []
	s = raw_input()
	for j in range(0, W):
		lst.append(s[j])
	field.append(lst)

for i in range(0, H):
	for j in range(0, W):
		if field[i][j] != '#':
			cnt = 0
			for p in range(-1, 2):
				if 0 <= i+p and i+p <= H-1:
					for q in range(-1, 2):
						if 0 <= j+q and j+q <= W-1:
							if field [i+p][j+q] == '#':
								cnt = cnt + 1
			field[i][j] = str(cnt)

for i in range(0, H):
	ans = ''
	for j in range(0, W):
		ans = ans + field[i][j]
	print ans