#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(c) (c).begin(), (c).end()
#define index_of(c, x) find(all(c), x) - (c).begin()

int solve(int n, const vector<int>& d) {
    vector<char> ex(1000, 0);
    rep(i, n) {
        int x = 0;
        rep(j, 3) {
            if (i + j >= n) break;
            x = x * 10 + d[i + j];
            ex[x] = 1;
        }
    }
    return index_of(ex, 0);
}

int main() {
    int n; cin >> n;
    vector<int> d(n);
    for (int& e : d) cin >> e;
    cout << solve(n, d) << endl;
}