#include using namespace std; int main () { int N; cin >> N; vector C(100010, 0); for (int i = 0; i < N; i ++) { int a; cin >> a; C[a] ++; } int fl = 0; int sum = 0; while (C[fl] >= 2) { sum += C[fl]; fl ++; } if (C[fl] == 0 || sum + C[fl] == N) { cout << fl << endl; return 0; } fl ++; while (C[fl] >= 2) { fl ++; } cout << fl << endl; }