def calc(array, i, j):
    ret = 0
    if i == 0 and j == 0:
        if array[1][0] == "#":
            ret += 1
        if array[0][1] == "#":
            ret += 1
        if array[1][1] == "#":
            ret += 1
        return ret
    if i == 0 and j == len(array[0])-1:
        if array[i][j-1] == "#":
            ret += 1
        if array[i+1][j-1] == "#":
            ret += 1
        if array[i+1][j] == "#":
            ret += 1
        return ret
    if i == len(array)-1 and j == 0:
        if array[i-1][j] == "#":
            ret += 1
        if array[i-1][j+1] == "#":
            ret += 1
        if array[i][j+1] == "#":
            ret += 1
        return ret
    if i == len(array)-1 and j == len(array[0])-1:
        if array[i][j-1] == "#":
            ret += 1
        if array[i-1][j] == "#":
            ret += 1
        if array[i-1][j-1] == "#":
            ret += 1
        return ret
    if i == 0:
        if array[i][j-1] == "#":
            ret += 1
        if array[i][j+1] == "#":
            ret += 1
        if array[i+1][j-1] == "#":
            ret += 1
        if array[i+1][j] == "#":
            ret += 1
        if array[i+1][j+1] == "#":
            ret += 1
        return ret
    if i == len(array)-1:
        if array[i][j-1] == "#":
            ret += 1
        if array[i][j+1] == "#":
            ret += 1
        if array[i-1][j-1] == "#":
            ret += 1
        if array[i-1][j] == "#":
            ret += 1
        if array[i-1][j+1] == "#":
            ret += 1
        return ret
    if j == 0:
        if array[i-1][j] == "#":
            ret += 1
        if array[i+1][j] == "#":
            ret += 1
        if array[i-1][j+1] == "#":
            ret += 1
        if array[i][j+1] == "#":
            ret += 1
        if array[i+1][j+1] == "#":
            ret += 1
        return ret
    if j == len(array[0])-1:
        if array[i-1][j] == "#":
            ret += 1
        if array[i+1][j] == "#":
            ret += 1
        if array[i-1][j-1] == "#":
            ret += 1
        if array[i][j-1] == "#":
            ret += 1
        if array[i+1][j-1] == "#":
            ret += 1
        return ret
    else:
        if array[i][j-1] == "#":
            ret += 1
        if array[i][j+1] == "#":
            ret += 1
        if array[i-1][j-1] == "#":
            ret += 1
        if array[i-1][j] == "#":
            ret += 1
        if array[i-1][j+1] == "#":
            ret += 1
        if array[i+1][j-1] == "#":
            ret += 1
        if array[i+1][j] == "#":
            ret += 1
        if array[i+1][j+1] == "#":
            ret += 1
        return ret


num = input().split()
num = [int(x) for x in num]

array = []
for h in range(num[0]):
    array.append(list(input()))

for i in range(num[0]):
    for j in range(num[1]):
        if array[i][j] == ".":
            array[i][j] = calc(array, i, j)
for i in range(0, len(array)):
    array[i] = [str(x) for x in array[i]]
    print("".join(array[i]))


### FIXED CODE ###

def calc(array, i, j, H, W):
    move = [[1, -1], [1, 0], [1, 1], [0, -1], [0, 1], [-1, 0], [-1, -1], [-1, 1]]
    num_mine = 0
    for k in range(8):
        x = i+move[k][0]
        y = j+move[k][1]
        if x >= H or x < 0 or y >= W or y < 0:
            pass
        else:
            num_mine += 1 if array[x][y] == "#" else 0
    return num_mine


def main():
    num = input().split()
    num = [int(x) for x in num]
    H = num[0]
    W = num[1]

    array = []
    for i in range(H):
        array.append(list(input()))

    for i in range(H):
        for j in range(W):
            if array[i][j] == "#":
                pass
            else:
                array[i][j] = calc(array, i, j, H, W)

    for i in range(0, num[0]):
        print("".join(map(str, array[i])))


if __name__ == '__main__':
    main()