def mirror_floor(floor):
    mirror_dict = {'0': '0', '1': '1', '2': '5', '5': '2', '8': '8'}
    mirror_floor_str = ''

    for digit in str(floor)[::-1]:
        if digit in mirror_dict:
            mirror_floor_str += mirror_dict[digit]
        else:
            return "INVALID"

    return int(mirror_floor_str)

k = int(input())
result = mirror_floor(k)
if result == "INVALID":
    print("INVALID")
else:
    print(result)
