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