H, W = map(int, raw_input().split())
S = [raw_input() for i in range(H)]
C = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        for di in range(-1, 1):
            if i + di < 0 or H <= i + di:
                continue
            for dj in range(-1, 1):
                if j + dj < 0 or W <= j + dj:
                    continue
                C[i][j] += 1 if S[i][j] == "#" else -1
for i in range(H):
    print "".join(C[i])


