def mirror_floor(floor):
    mirror_numbers = {'0': '0', '1': '1', '2': '5', '5': '2', '8': '8'}
    mirrored_floor = ""

    for digit in reversed(str(floor)):
        mirrored_number = mirror_numbers.get(digit, digit)
        mirrored_floor += mirrored_number

    return int(mirrored_floor)

k = int(input())

result = mirror_floor(k)
print(result)