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