num = int(input())

if num > 0:
    def reverse_and_replace(num):
        reversed_num = str(num)[::-1]
        result = ''
        zeros_removed = False
        for idx, digit in enumerate(reversed_num):
            if digit == '5':
                result += '2'
            elif digit == '2':
                result += '5'
            elif digit != '0' or (digit == '0' and (idx != 0 and idx != len(reversed_num)-1)):
                result += digit
                if digit != '0':
                    zeros_removed = True
        if not zeros_removed:
            result = result[:-1]
        return int(result)

    print(reverse_and_replace(num))
else:
    print(num)
