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

    k_str = str(k)

    mirror_k_str = ""

    for digit in reversed(k_str):
        if digit in mirror_dict:
            mirror_k_str += mirror_dict[digit]
        else:
            mirror_k_str += digit

    return str(int(mirror_k_str))


k = int(input())

result = mirror_floor(k)
print(result)
