#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;

class BoyerMoore {
    public:
    string text;
    string pattern;
    int n;
    int m;
    map<char, int> lambda;
    BoyerMoore(string text_, string pattern_) : 
        text(text_), pattern(pattern_), n(text_.size()), m(pattern_.size()) {
        compute_lambda();
    };
    void compute_lambda() {
        for(int j = 1; j <= m; j++) {
            lambda[pattern.at(j - 1)] = j;
        }
    };
    int get_lambda(const char& c) {
        if (lambda.find(c) != lambda.end()) {
            return lambda[c];
        } else {
            return 0;
        }
    };
    bool match() {
        int s = 0;
        while(s <= n - m) {
            int j = m;
            while(j > 0 && pattern.at(j - 1) == text.at(s + j - 1)) {
                j--;
            }
            if(j == 0) {
                return true;//ここを消すとsが文字列の位置を示す
                s++;
            } else {
                s += std::max(1, j - get_lambda(text.at(s + j - 1)));
            }
        }
        return false;
    };
};

template <class BidirectionalIterator>
bool generic_next_permutation(BidirectionalIterator first, BidirectionalIterator last) {
    //要素が０又は１の場合終了
    if (first == last) return false;
    BidirectionalIterator second = first;
    ++second;
    if (second == last) return false;
    BidirectionalIterator i = last;
    --i;   //itを最後尾にセット
    while (true) {
        BidirectionalIterator prev_i = i;
        if (*(--i) < *prev_i) {
            BidirectionalIterator j = last;
            while (!(*i < *--j));
            swap(*i, *j);
            reverse(prev_i, last);
            return true;
        }
        if (i == first) {
            reverse(first, last);
            return false;
        }
    }
}

int main(void){

    int n;
    cin>>n;
    vc v(n);
    rep(i,n)cin>>v[i];
    string s="";
    rep(i,n)s+=v[i];
    string ans="00000";
    // fin(s);
    for(int i=0;i<50000;i++){
        string tmp=ans;
        while(tmp.size()>1){
            if(tmp[0]=='0'){
                tmp.erase(tmp.begin());
            }else break;
        }
        BoyerMoore bm(s,tmp);
        if(!bm.match()){
            fin(tmp);
            return 0;
        }
        ans=to_string(STI(ans)+1);
        // cout<<ans<<endl;
    }

}


Measured memory_bytes: 3300