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

#define N 1000

static char d[N];
static int n;

static void
reverse(d)
char *d;
{
  int i, j;
  
  for (i = 0, j = strlen(d) - 1; i < j; ++i, --j) {
    const char t = d[i];
    d[i] = d[j];
    d[j] = t;
  }
}

static
find(u)
{
  char s[16];
  int i;
  
  for (i = 0; ; ++i) {
    s[i] = u % 10 + '0';
    u /= 10;
    if (u == 0) break ;
  }
  s[i + 1] = '\0';
  return !!(strstr(d, s) != NULL);
}

main()
{
  int i;
  
  scanf("%d", &n);
  for (i = 0; i < n; ++i)
    scanf(" %[0-9]", &d[i]);
  d[n] = '\0';
  reverse(d);

  for (i = 0; ; ++i) {
    if (!find(i)) {
      printf("%d\n", i);
      break ;
    }
  }

  return EXIT_SUCCESS;
}