def mirror_floor_number(k):
    k_str = str(k)[::-1]
    mirrored_digits = {'0': '0', '1': '1', '2': '5', '5': '2', '8': '8'}


    mirrored_str = ''.join(mirrored_digits[c] if c in mirrored_digits else c for c in k_str)

    mirrored_number = int(mirrored_str)
    return mirrored_number

k = int(input())

mirrored_result = mirror_floor_number(k)
print(mirrored_result)
