H,W = map(int, input().split())
board = []
for i in range(0,H):
	board.append(input())
board = list(board)
dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]
for i in range(0,H):
	for j in range(0,W):
		if board[i][j] == '#':
			continue
		num = 0
		for k in range(0, 8):
			ni = i + dy[k]
			nj = j + dx[k]
			if (ni < 0) or (H <= ni):
				continue
			if (nj < 0) or (W <= nj):
				continue
			if board[ni][nj] == '#':
				num += 1
		board[i][j] = str(num)
		
	for i in range(0,H):
		print(board[i])
