def mirror_floor_number(k):
    k_str = str(k)
    mirrored_k_str = ""

mirror_digits = {
'0': '0',
'1': '1',
'2': '5',
'5': '2',
'8': '8',
}

for digit in k_str:
    if digit in mirror_digits:
    mirrored_k_str = mirror_digits[digit] + mirrored_k_str
else:
    mirrored_k_str = digit + mirrored_k_str

    mirrored_k = int(mirrored_k_str)

    return mirrored_k


k = input()
result = mirror_floor_number(k)
print(result)