import sys

if sys.platform =='ios':
	sys.stdin=open('input.txt')

h, w = [int(x) for x in input().split()]
board = [input() for _ in range(h)]

mines=['' for _ in range(h)]

print(board)

for row in range(h):
	for col in range(w):
		if board[row][col] != '#':
			counts = 0
			dx = [x for x in range(-1, 2) if (col+x>=0 and col+x<w)]
			dy = [y for y in range(-1, 2) if (row+y>=0 and row+y<h)]
			#print('row:{}, col:{}, dx:{}, dy:{}'.format(row,col,dx,dy))
			for x in dx:
				for y in dy:
					#print('row+y:{}, col+x:{}'.format(row+y, col+x))
					if board[row+y][col+x] == '#':
						counts += 1
			mines[row] += str(counts)
		else:
			mines[row] += '#'
for mine in mines:
	print(mine)