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

#define REP(i,n) for (int i=0;i<(n);i++)

int main() {
  int N;
  cin >> N;
  string D;
  REP(i, N) {
    int Di;
    cin >> Di;
    D.push_back('0' + Di);
  }
  int ans = 0;
  while (true) {
    if (D.find(to_string(ans)) == string::npos) {
      cout << ans << endl;
      return 0;
    }
    ++ans;
  }
}