H, W = map(int, input().split())
grid = [['']*W for i in range(H)]
s = list([['.']*W for i in range(H)])

for i in range(H):
    grid[i] = input()
    s[i] = list(grid[i])

for h in range(H):
    for w in range(W):
        count = 0
        try:
            if s[h-1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h-1][w] == '#':
                count+=1
        except:
            None
        try:
            if s[h-1][w+1] == '#':
                count+=1
        except:
            None
        try:
            if s[h][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h][w+1] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w+1] == '#':
                count+=1
        except:
            None
        if count > 0:
            s[h][w] = str(count)

for h in range(H):
    print(''.join(s[h]))