#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, d[1000];
unordered_set<int> s;

int main(){
	cin >> n;
	rep(i, n) cin >> d[i];
	rep(i, n){
		int x = 0;
		for(int j = i; j < n; j++){
			x *= 10;
			x += d[j];
			if(x > 100000) break;
			s.insert(x);
		}
	}
	for(int i = 0; ; i++) if(!s.count(i)){
		cout << i << endl;
		break;
	}
	
	return 0;
}