#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }

    set<int> seq;
    for (int i = 0; i < n; ++i) {
        int m = 0;
        for (int j = 0; j < 3 && i + j < n; ++j) {
            m *= 10;
            m += d[i + j];
            seq.insert(m);
        }
    }

    for (int i = 0; i < 1000; ++i) {
        if (seq.find(i) == seq.end()) {
            cout << i << endl;
            break;
        }
    }


    return 0;
}