h, w = map(int, input().split())
s = [input() for _ in range(h)]
dx = [1,1,1,-1,-1,-1,0,0]
dy = [0,1,-1,0,1,-1,1,-1]
for i in range (h):
	z=[]
	for j in range (w):
		if(s[i][j] == "."):
			cnt = 0
			for k in range (8):
				x = i + dx[k]
				y = j + dy[k]
				if(x >= 0 and x < h and y >= 0 and y < w and s[x][y] == "#"):
					cnt += 1
			z.append(cnt)
		else:
			z.append("#")
	print (*z, sep="")