// Aizu 1356: Decimal Sequences
// 2017.9.19 bal4u@uu

#include <stdio.h>
#include <string.h>

char f[1003];

int main()
{
	int n, i, d, a;

	scanf("%d", &n);
	memset(f, 0, sizeof(f)), a = 0, f[1000] = 1;
	while (n-- > 0) {
		scanf("%d", &d);
		f[d] = 1;
		a = 10*a + d; f[a%100] = 1, a %= 1000, f[a] = 1;
	}
	for (i = 0; f[i]; i++);
	printf("%d\n", i);
	return 0;
}