//
//  main.swift
//  TestSpace for AtCoder
//
//  Created by Koichi Okai on 2020/06/25.
//  Copyright © 2020 Koichi Okai. All rights reserved.
//

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let _ = Int(readLine()!)!
    
    let a = readInts().sorted()
    
    let val = a.reduce(0) { $0 + $1 } - a[0]
    

    var b = a
    
    let t = b[0]
    b[0] = b[1]
    b[1] = t
    
    let val2 = b.reduce(0) { $0 + $1 } - b[0]
    
    print(val > val2 ? val : val2)
}

main()
