h,w=map(int,input().split())
s=['-'*(w+2)]
for i in range(h):
    s.append('-'+input()+'-')
s.append('-'*(w+2))
for j in range(1,h+1):
    t=[]
    for k in range(1,w+1):
        if s[j][k]=='#':
            t.append('#')
        else:
            c=[s[j-1][k-1],s[j][k-1],s[j+1][k-1],s[j-1][k],s[j+1][k],s[j-1][k+1],s[j][k+1],s[j+1][k+1]]
            t.append(str(c.count('#')))
    t=''.join(t)
    print(t)
