h,w = (int(i) for i in input().split())
x = [input() for i in range(h)]
for i in range(h):
	answer = ""
	for j in range(w):
		if x[i][j] == ".":
			num,y = 0,[[i-1,j-1],[i-1,j],[i-1,j+1],[i,j-1],[i,j+1],[i+1,j-1],[i+1,j],[i+1,j+1]]
			for k in y:
				if -1<k[0] and k[0]<h and -1<k[1] and k[1]<w:
					if x[k[0]][k[1]] == "#":
						num += 1
			answer += str(num)
		else:
			answer += "#"
	print(answer)