#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=20001;
int a[maxn],b[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){	 
     b[a[i]]++;
	 if(i+1<=n) 
     b[a[i]*10+a[i+1]]++;
     if(i+2<=n)
	 b[a[i]*100+a[i+1]*10+a[i+2]]++;
	 if(i+3<=n)
	 b[a[i]*1000+a[i+1]*100+a[i+2]*10+a[i+3]]++;
    }
	for(int i=0;i<=10000;i++)
	if(!b[i]){
	cout<<i<<endl;
	break;
    }
   // while(1);
	return 0;
}