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

#define int long long

bool used[100000000] = {};

signed main() {
  int n;
  cin >> n;

  vector<int> d(n);
  for ( int i = 0; i < n; i++ ) cin >> d[i];

  for ( int i = 1; i < 7; i++ ) {
    for ( int j = 0; j <= n-i; j++ ) {
      int num = 0;
      for ( int k = j; k < j+i; k++ ) {
	num *= 10;
	num += d[k];	
      }
      used[num] = true;      
    }
  }

  for ( int i = 0; i < 100000000; i++ ) {
    if ( !used[i] ) {
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}

