H,W = map(int,input().split())
masu = [list(input()) for _ in range(H)]

def kazu(h,w):
    houkou = [[1,0],[1,-1],[0,-1],[-1,-1],[-1,0],[-1,1],[0,1],[1,1]]
    count = 0
    for ya in houkou:
        try:
            if masu[h+ya[0]][w+ya[1]] == '#':
                count += 1
        except:pass
    return count

for w in range(W):
    for h in range(H):
        if masu[h][w]=='.':
            masu[h][w] = kazu(h,w)

for l in masu:print(*l,sep='')
            