H,W = list(map(int,input().split()))
S = [list(input().replace('.','0')) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#': continue
        for k in [-1,0,1]:
            for l in [-1,0,1]:
                if 0 <= i+k <= H-1 and 0 <= j+l <= W-1 and S[i+k][j+l] == '#':
                    S[i][j] = str(int(S[i][j])+1)
for s in S:
    print(''.join(s))