#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,a[1000];
set<int> st;
int main(){
	cin>>N;
	rep(i,N) cin>>a[i];
	rep1(K,4){
		rep(j,N+1-K){
			int x=0;
			rep(k,K) x=x*10+a[j+k];
			st.insert(x);
		}
	}
	rep(i,10000){
		if(!binary_search(all(st),i)){
			cout<<i<<endl;
			return 0;
		}
	}
}