h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
map=[[ int(0) for i in range(w)] for j in range(h)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='#':
			map[i][j]='#'
		else:
			for k in range(-1,2):
				for p in range(-1,2):
					if 0<=i+k and i+k<h and 0<=j+p and j+p<w and s[i+k][j+p]=='#':
						map[i][j]+=1
			map[i][j]=str(map[i][j])
for i in range(h):	
	print(''.join(map[i]))