h, w = map(int,input().split())
a = ["."+input()+"." for _ in range(h)]
a.insert(0,"."*(w+2))
a.append("."*(w+2))
y = [1,1, 1,-1,-1,-1,0, 0]
x = [0,1,-1, 0, 1,-1,1,-1]
for i in range(1,h+1):
    l =[]
    for j in range(1,w+1):
        if a[i][j] == "#":
            l += "#"
        else: l += str(sum([1 for k in range(8) if a[i+y[k]][j+x[k]] == "#"]))
    print("".join(l))