#include <cstdio>
using namespace std;
int n;
int d[1005];
bool vis[1005];
void dfs(int now,int bs,int ans)
{
	if (bs>3||now>n) return;
	ans=ans*10+d[now];
	vis[ans]=1;
	dfs(now+1,bs+1,ans);
}
int main()
{
	register int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&d[i]);
		vis[d[i]]=1;
	}
	for (i=1;i<=n;i++) 
	if (d[i]!='0') dfs(i,0,0);
	for (i=0;i<=1000;i++)
	if (!vis[i])
	{
		printf("%d\n",i);
		return 0;
	}
}