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