h,w=map(int,input().split())
s=list(input()for _ in range(h))
dx=[0,1,0,-1,1,1,-1,-1]
dy=[1,0,-1,0,1,-1,1,-1]
for i in range(h):
	for j in range(w):
		if s[i][j]=='.':
			c=0
			for r in range(8):
				x=i+dx[r]
				y=j+dy[r]
				c+=0<=x<h and 0<=y<w and s[x][y]=='#'
			print(c,end='')
		else:print('#',end='')
	print()