k = int(input())
mirror = {'0': '0', '1': '1', '2': '5', '5': '2', '8': '8'}
def get_mirror(num):
    num_str = str(num)
    mirrored_str = ''
    for digit in num_str:
        if digit in mirror:
            mirrored_str = mirror[digit] + mirrored_str
        else:
            return None
    return int(mirrored_str)

result = get_mirror(k)
if result is not None:
    print(result)
