dx=[1,1,1,0,0,-1,-1,-1]
dy=[-1,0,1,-1,1,-1,0,1]
n,m=map(int,input().split())
s=list()
for i in range(n):
	s.append(input())
ans=[[0 for i in range(n+5)]for i in range(m+5)]
for i in range(n):
	for j in range(m):
		if s[i][j]=='#':
			ans[i][j]='#';
		else:
			t=0
			for k in range(8):
				xx=i+dx[k]
				yy=j+dy[k]
				if xx>=0 and yy>=0 and xx<n and yy<m and s[xx][yy]=='#':
					t+=1
			ans[i][j]=t

for i in range(n):
	for j in range(m):
		print(ans[i][j],end='')
	print('')