h,w = map(int,input().split())
grid = ["."*(w+2)]+["."+input()+"." for _ in range(h)]+["."*(w+2)]
for y in range(1,h+1):
	for x in range(1,w+1):
		if grid[y][x]=="#":
			print("#",end="")
		else:
			print(sum(grid[i][j]=="#" for i in range(y-1,y+2) for j in range(x-1,x+2)),end="")
	print("")