h, w = map(int, input().split())
S=[["."]+list(input())+["."] for i in range(h)]
S=[["."]*(w+2)]+S+[["."]*(w+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if S[i][j] == ".":
            S[i][j] = (str([S[i-1][j], S[i+1][j], S[i][j-1], S[i][j+1], S[i-1][j-1], S[i-1][j+1], S[i+1][j-1], S[i+1][j+1]].count("#")))
for k in range(len(S[1:h+1])):
    print(*S[1:h+1][k][1:w+1], sep="")