#include <bits/stdc++.h>
using namespace std;

typedef int Digit[5];

int n;
int ds[114514];

int Convert(int t, int *ds) {
  if (t == 0) {
    ds[0] = 0;
    return 1;
  }

  int cnt = 0;
  while (t > 0) {
    ds[cnt++] = t%10;
    t /= 10;
  }
  reverse(ds, ds+cnt);
  return cnt;
}

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d", &ds[i]);
  }

  int ans = 0;
  while (1) {
    Digit gs;
    int k = Convert(ans, gs);
    bool fail = false;
    for (int i=0; i<=n-k; i++) {
      int cnt = 0;
      for (int j=0; j<k; j++) {
        cnt += (ds[i+j] == gs[j]);
      }

      if (cnt == k) {
        fail = true;
        break;
      }
    }

    if (!fail) break;
    ans++;
  }

  printf("%d\n", ans);
}