# coding: utf-8
range = xrange
H, W = map(int, raw_input().split(' '))
S = [[c for c in raw_input()] for _ in range(H)]

answer = []
for h in range(H):
    row = []
    for w in range(W):
        if S[h][w] == '.':
            row.append([
                S[i][j]
                for i in range(max(h - 1, 0), min(H, h + 2))
                for j in range(max(w - 1, 0), min(W, w + 2))
            ].count('#'))
        else:
            row.append(S[h][w])
    answer.append(row)

for r in answer:
    print u''.join(map(unicode, r))
