h,w = map(int,input().split())
s=[[x for x in input()] for i in range(h)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='.':
			count=0
			for di in range(-1,2):
				for dj in range(-1,2):
					if not(0<=i+di<h and 0<=j+dj<w): pass
					elif s[i+di][j+dj]=="#":
						count += 1
			s[i][j]=str(count)
	print(''.join(s[i]))