h,w=map(int,input().split())
s=["."*(w+2)]
for i in range(h):
	s.append("."+input()+".")
s.append("."*(w+2))
for i in range(1,h+1):
	p=""
	for j in range(1,w+1):
		if s[i][j]==".":
			x=s[i-1][j-1:j+2]+s[i][j-1:j+2]+s[i+1][j-1:j+2]
			p+=str(x.count("#"))
		else:
			p+="#"
	print(p)
