h, w = [ int(v) for v in input().split() ]
field = [ list(input()) for i in range(h) ]
ansfield = [ [ "#" for j in range(w)] for i in range(h)]
for i in range(h):
	for j in range(w):
		if field[i][j] == ".":
			ansfield[i][j] =  str(sum([ [ field[i][j] for j in range(max(j-1,0),min(w,j+2)) ].count("#") for i in range(max(i-1,0),min(h,i+2)) ]))

for i in range(h):
	print("".join(ansfield[i]))