#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+14;
int n, arr[maxn];
void solve(){
cin >> n;
int idx = 1, a = - 1e9, b = - 1e9;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
if (arr[i] > a) {
a = arr[i];
idx = i;
}
}
for (int i = 1; i <= n; i++) {
if (i == idx) continue;
b = max(b, arr[i]);
}
cout << a + b;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("input.txt","r")){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhuPTFlNisxNDsKaW50IG4sIGFyclttYXhuXTsKdm9pZCBzb2x2ZSgpewoJY2luID4+IG47CglpbnQgaWR4ID0gMSwgYSA9IC0gMWU5LCBiID0gLSAxZTk7IAoJZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CgkJY2luID4+IGFycltpXTsKCQlpZiAoYXJyW2ldID4gYSkgewoJCQlhID0gYXJyW2ldOwoJCQlpZHggPSBpOwoJCX0KCX0gCglmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKCQlpZiAoaSA9PSBpZHgpIGNvbnRpbnVlOwoJCWIgPSBtYXgoYiwgYXJyW2ldKTsKCX0KCQoJY291dCA8PCBhICsgYjsKfQppbnQgbWFpbigpewoJaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKCWNpbi50aWUoMCk7ICAgIGNvdXQudGllKDApOwoJaWYgKGZvcGVuKCJpbnB1dC50eHQiLCJyIikpewoJCWZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKTsKCQlmcmVvcGVuKCJvdXRwdXQudHh0IiwidyIsc3Rkb3V0KTsKCX0KCXNvbHZlKCk7CglyZXR1cm4gMDsKfQo=