h,w = map(int,input().split())
l = list('.'+input()+'.' for _ in range(h))
l = ['.'*(w+2)] + l + ['.'*(w+2)]

for i in range(1,h+1):
    ans=''
    for j in range(1,w+1):
        if l[i][j] == '#':
            ans += '#'
        else:
            _tmp = l[i-1][j-1:j+2]+l[i][j-1:j+2]+l[i+1][j-1:j+2]
            ans+=str(_tmp.count('#'))
    print(ans)