#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; bool alt = true; while (C[fl] >= 2) { sum += C[fl]; alt = alt && (C[fl] == 2); fl ++; } if (C[fl] == 0 || (sum + C[fl] == N && alt)) { cout << fl << endl; return 0; } fl ++; while (C[fl] >= 2) { fl ++; } cout << fl << endl; }