h,w=map(int,raw_input().split())
temp=[]
e='eee'
for i in range(w-1):
	e='e'+e
temp.append(e)	
for i in range(h):
	ip=raw_input()
	ip='e'+ip+'e'
	temp.append(ip)
temp.append(e)
n=0
op=[]	
fop=[]
for i in range(h):
	for j in range(w):
		if temp[i+1][j+1]=='.':
			if temp[i+2][j+1]=='#':
				n=n+1
			if temp[i][j+1]=='#':
				n=n+1
			if temp[i+1][j+2]=='#':
				n=n+1
			if temp[i+1][j]=='#':
				n=n+1
			if temp[i+2][j+2]=='#':
				n=n+1	
			if temp[i][j+2]=='#':
				n=n+1
			if temp[i+2][j]=='#':
				n=n+1	
			if temp[i][j]=='#':
				n=n+1
			op.append(str(n))	
			n=0
		elif temp[i+1][j+1]=='#':
			op.append('#')
	fop.append(op)
	op=[]

for i in range(h):
	print ''.join(fop[i])