#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    hash<string> hs;

    set<int> ss;
    for (int i = 0; i < n; i++) {
        if (as[i] == 0) {
            ss.insert(hs("0"));
            continue;
        }
        string t = "";
        for (int j = i; j < n; j++) {
            t += as[j] + '0';
            ss.insert(hs(t));
        }
    }

    for (int i = 0;; i++) {
        if (!ss.count(hs(to_string(i)))) {
            cout << i << endl;
            return 0;
        }
    }
}
