#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> n; vector cnt(100100, 0); rep(i,n){ int a; cin >> a; cnt[a]++; } if(n==1){ cout << 0 << '\n'; return 0; } int i = 0; bool ok = true; for(;;i++){ if(!cnt[i]) break; if(ok){ if(cnt[i]<3) ok = false; }else{ if(cnt[i]<2) break; } } cout << i << '\n'; return 0; }