#075_B
h,w=map(int,input().split())
s=['.'*(w+2)]+[list('.'+input()+'.') for _ 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]=sum([s[i+_i][j+_j]=='#' for _i in range(-1,2) for _j in range(-1,2)])
    print(*s[i][1:w+1],sep='')