h,w = map(int, input().split())
S = [input() for i in range(h)]
for r in range(h):
    l = ''
    for c in range(w):
        if S[r][c] == '#':
            l += '#'
        else:
            l += str(sum([x[max(0,c-1):min(c+2,w)].count('#') for x in S[max(0,r-1):min(r+2,h)]]))
    print(l)