#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

string itos(int num){
  string res;
  if(num == 0) return "0";
  while(num!=0) res+=num%10+'0',num/=10;
  reverse(res.begin(),res.end());
  return res;
}

int main() {
  int n,a[1001]={};
  cin>>n;
  for(int i=0;i<n;i++) cin >> a[i];

  int  num=0;
  while(1){
    string str=itos(num);
    int flg=0;
    for(int i=0;i<n;i++){
      flg = 0;
      while(flg+i<n&&a[i+flg]==str[flg]-'0')flg++;
      if(flg == str.size())break;
    }
    if(flg != str.size())break;
    num++;
  }
  cout << num <<endl;
}