H,W=map(int,raw_input().split(' '))

m=['.']*((H+2)*(W+2))

for h in range(1,H+1):
    S=raw_input()
    i=0
    for w in range(1,W+1):
        m[h*(W+2)+w]=S[i]
        i+=1

r=[0]*(H*W)
i=0
for h in range(1,H+1):
    for w in range(1,W+1):
        p=h*(W+2)+w
        if m[p]=='#':
            r[i]='#'
        else:
            if m[p-(W+2)-1]=='#':
                r[i]+=1
            if m[p-(W+2)]=='#':
                r[i]+=1
            if m[p-(W+2)+1]=='#':
                r[i]+=1
            if m[p-1]=='#':
                r[i]+=1
            if m[p+1]=='#':
                r[i]+=1
            if m[p+(W+2)-1]=='#':
                r[i]+=1
            if m[p+(W+2)]=='#':
                r[i]+=1
            if m[p+(W+2)+1]=='#':
                r[i]+=1
        i+=1

r=map(str,r)
for h in range(H):
    print ''.join(r[h*W:h*W+W])