#include <bits/stdc++.h>

using namespace std;

#define reep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) reep(i,0,n)

int exi[10000];


int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	rep(i,n-2){
		int t=v[i]*100+v[i+1]*10+v[i+2];
		exi[t]=1;
	}
	//cout<<"A"<<endl;
	rep(i,n-1){
		int t=v[i]*10+v[i+1];
		exi[t]=1;
	}
	//cout<<"B"<<endl;
	rep(i,n){
		exi[v[i]]=1;
	}
	//cout<<"C"<<endl;
	rep(i,10000){
		if(exi[i]==0){
			cout<<i<<endl;
			return 0;
		}
	}
}