H, W = map(int,input().split())
s = [input() for i in range(H)]
for i in range(H):
    l = ""
    for j in range(W):
        if s[i][j] == "#":
            l += "#"
        else:
            l += str(sum([t[max(0,j-1):min(W,j+2)].count("#") for t in s[max(0,i-1):min(H,i+2)]]))
    print(l)