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

dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]

cnt=0
for i in range(H):
	for j in range(W):
		if a[i][j]==".":
			cnt=0
			for k in range(8):
				#print dx[k],dy[k]
				x=i+dx[k]
				y=j+dy[k]
				if x>=0 and x<H and y>=0 and y<W and a[x][y]=="#":
					cnt+=1
			a[i][j]=cnt
			#print i,j,cnt


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