H,W=list(map(int,raw_input().split()))
a = []
for i in range(H):
    a.append(list(raw_input()))
#print a

cnt=0
for i in range(H):
	for j in range(W):
		#print i,j
		if i-1>-1 and j-1>-1 and a[i-1][j-1]=="#":cnt+=1
		if i-1>-1 and a[i-1][j]=="#":cnt+=1
		if i-1>-1 and j+1<W and a[i-1][j+1]=="#":cnt+=1
		if j+1<W and a[i][j+1]=="#":cnt+=1
		if j-1>-1 and a[i][j-1]=="#":cnt+=1
		if j-1>-1 and i+1<H and a[i+1][j-1]=="#":cnt+=1
		if i+1<H and a[i+1][j]=="#":cnt+=1
		if i+1<H and j+1<W and a[i+1][j+1]=="#":cnt+=1
		
		#print i,j,cnt
		if a[i][j]==".":
			a[i][j]=cnt
		cnt=0
			


for i in range(H):
	maped_num = map(str, a[i])
	s = ''.join(maped_num)
	print s