def mirror_digit(d):
    mirror_dict = {
        '0': '0',
        '1': '1',
        '2': '5',
        '5': '2',
        '8': '8',
        '9': '6',
    }
    return mirror_dict.get(d, d)

def mirror_floor(k):
    mirrored_str = str(k)[::-1]
    mirrored_result = ''.join(mirror_digit(d) for d in mirrored_str)
    return str(int(mirrored_result))
k = int(input())
result = mirror_floor(k)
print(result)
