#include <iostream>
using namespace std;

int pow(int n) {
  int p = 1;
  for (int i = 0; i < n; i++)
    p *= 10;
  return p;
}

int calclen(int n) {
  int count = 0;
  while (n > 0) {
    n /= 10;
    count++;
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  for (int num = 0; ; num++) {
    int len;
    if (num == 0) len = 1; 
    else len = calclen(num);
    bool flag = false;
    for (int i = 0; i + len - 1 < n; i++) {
      int t = 0;
      for (int j = 0; j < len; j++) {
	t += a[i + j] * pow(len - j - 1);
      }
      if (t == num) {
	flag = true;
      }
    }
    if (flag == false) {
      cout << num << endl;
      return 0;
    }
  }
}