def mirror_number(k):
    k_str = str(k)
    reversed_str = k_str[::-1]
    mirror_str = ''
    
    for digit in reversed_str:
        if digit == '6':
            mirror_str += '6'
        elif digit == '9':
            mirror_str += '9'
        elif digit == '0' or digit == '1' or digit == '8':
            mirror_str += digit
        elif digit == '2':  
            mirror_str += '5'         
        elif digit == '5':
            mirror_str += '2'
        elif digit == '3':
            mirror_str += '3'
        elif digit == '4':
            mirror_str += '4'
        elif digit == '7':
            mirror_str += '7'
        else:
            return 'Invalid digit'
    
    return int(mirror_str)


k = int(input())
result = mirror_number(k)
print(result)