#include int main () { int n = 0; int a = 0; int res = 0; int rem = 0; int cnt[100001] = {}; int ans = 0; res = scanf("%d", &n); for (int i = 0; i < n; i++) { res = scanf("%d", &a); cnt[a]++; } rem = n; while (cnt[ans] > 1) { rem -= cnt[ans]; ans++; } if (cnt[ans] > 0 && rem > 1) { ans++; } printf("%d\n", ans); return 0; }