#include using namespace std; int main() { int N; cin >> N; vector A(N), cnt(100001); for( int i = 0; i < N; i++ ) { cin >> A[i]; cnt[A[i]]++; } bool flag = true, ge_two = false; sort(A.begin(), A.end()); for( int i = 0; i <= 100000; i++ ) { if( cnt[i] == 0 ) { cout << i << endl; break; }else if( cnt[i] == 1 ) { if( flag ) { if( A[N-1] == i ) { if( !ge_two ) { cout << 0 << endl; break; } }else { cnt[i]++; cnt[A[N-1]]--; } flag = true; }else { cout << i << endl; } }else { ge_two = true; } } }