import copy
h,w=map(int,input().split())
s=[]
for i in range(h):
	s.append(list(input()))

copyS=copy.deepcopy(s)


def check(y,x,s):
	ans=0
	for i in range(3):
		for j in range(3):
			X=x+i-1
			Y=y+j-1
			if 0<=X<w and 0<=Y<h:
				if s[Y][X]=="#":
					ans+=1
	return ans

for i in range(h):
	for j in range(w):
		if s[i][j]==".":
			copyS[i][j]=str(check(i,j,s))

for i in copyS:
	print("".join(i))
