// हर हर महादेव using namespace std; #include #define ll long long int #define ld long double #define uid(a, b) uniform_int_distribution(a, b)(rng) mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count()); #ifdef shivang_ka_laptop #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); #define booga cerr << "booga" << endl; #else #define debug(...) 42; #define booga 9; #endif template std::ostream& operator<<(std::ostream& stream, const vector& vec){ for(size_t i = 0; i < vec.size(); i++){stream << vec[i];if(i != vec.size() - 1)stream << ' ';}; return stream; } template std::istream& operator>>(std::istream& stream, vector& vec) { for(T &x : vec)stream >> x;return stream; } template std::ostream& operator<<(std::ostream& stream, const pair& pr){ stream << pr.first << ' ' << pr.second; return stream; } template std::istream& operator>>(std::istream& stream, pair& pr){ stream >> pr.first >> pr.second; return stream; } template void operator+=(vector& vec, const U value) { for(T &x : vec)x += value; } template void operator-=(vector& vec, const U value) { for(T &x : vec)x -= value; } template void operator*=(vector& vec, const U value) { for(T &x : vec)x *= value; } template void operator/=(vector& vec, const U value) { for(T &x : vec)x /= value; } template void operator++(vector& vec) { vec += 1; } template void operator++(vector& vec,int) { vec += 1; } template void operator--(vector& vec) { vec -= 1; } template void operator--(vector& vec,int) { vec -= 1; } template void operator+=(pair& vec, const V value) { vec.first += value;vec.second += value; } template void operator-=(pair& vec, const V value) { vec.first -= value;vec.second -= value; } template void operator*=(pair& vec, const V value) { vec.first *= value;vec.second *= value; } template void operator/=(pair& vec, const V value) { vec.first /= value;vec.second /= value; } template void operator++(pair& vec) { vec += 1; } template void operator++(pair& vec,int) { vec += 1; } template void operator--(pair& vec) { vec -= 1; } template void operator--(pair& vec,int) { vec -= 1; } template string to_string(pair p); template string to_string(tuple p); template string to_string(tuple p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(char c) {string s;s += c;return s; } string to_string(const char* s) {return to_string((string) s); } string to_string(bool b) {return (b ? "1" : "0"); } string to_string(vector v) {bool first = true;string res = "{";for (int i = 0; i < static_cast(v.size()); i++) {if (!first) {res += ", ";}first = false;res += to_string(v[i]);}res += "}";return res;} template string to_string(bitset v) {string res = "";for (size_t i = 0; i < N; i++) {res += static_cast('0' + v[i]);}return res;} template string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;} template string to_string(pair p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} template string to_string(tuple p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";} template string to_string(tuple p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";} template bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);} void bharo(int N_N) { return; }template void bharo(int N_N, Head &H, Tail & ... T) {H.resize(N_N);bharo(N_N,T...);} void safai() { return; }template void safai(Head &H, Tail & ... T) {H.clear();safai(T...);} void testcase(){ int n; cin >> n; vector a(n); map freq; for(int i = 0; i < n; i++){ cin >> a[i]; freq[a[i]]++; } int gon = 0; bool hua = false; for(int i = 0; i <= n+5; i++){ if(freq[i] >= 2){ gon += 2; continue; } if(hua || freq[i] == 0){ cout << i; return; } hua = true; gon++; int av = n - gon; if(av < 1){ cout << i; return; } gon++; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); int tt = 1; //cin >> tt; while(tt--){ testcase(); } return (0-0); }