h,w = map(int,input().split())
s = [[0]*(w+2)]+[[0]+[(i == "#")*1 for i in list(input())]+[0] for _ in range(h)]+[[0]*(w+2)]

ans = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i+1][j+1] == 1:
            ans[i][j] = "#"
            continue
        ans[i][j] = str(s[i][j+1]+s[i+1][j]+s[i+1][j+2]+s[i+2][j+1]+s[i][j]+s[i+2][j+2]+s[i+2][j]+s[i][j+2])
for l in ans:
    print("".join(l))