h,  w =  map(int, input().split())
a = []
a.append("."*(w+2))
for _ in  range(h):
    a.append("."+input()+".")
a.append("."*(w+2))

for i in range(1, h+1):
    ans = ""
    for j in range(1, w+1):
        if a[i][j] == ".":
            ans += str([a[i-1][j-1], a[i-1][j], a[i-1][j+1], a[i][j-1], a[i][j+1], a[i+1][j-1], a[i+1][j], a[i+1][j+1]].count("#"))
        else:
            ans += "#"
    print(ans)