a=str(input())
b=int(str(a[::-1]))
b = str(b)
if int(a)==int(b[::-1]):
    a = str(a)
    a = a.replace('2','g')
    a = a.replace('5','2')
    a = a.replace('g','5')
    print(a[::-1])
else:
    b = str(b)
    b = b.replace('2','g')
    b = b.replace('5','2')
    b = b.replace('g','5')
    print(b)
