#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

class Int {
public:
	string s;
	Int(int i);
	Int operator++();
	bool operator<(Int i);
};
Int::Int(int i) {
	s = to_string(i);
}
Int Int::operator++() {
	for (int i = s.size() - 1; i >= 0; i--) {
		if ('0' <= s[i] && s[i] < '9') {
			s[i]++;
			break;
		}
		else s[i] = '0';
	}
	if (s[0] == '0')s = '1' + s;
	return *this;
}
bool Int::operator<(Int i) {
	if (s.size() != i.s.size())return s.size() < i.s.size();
	return s < i.s;
}
ostream&operator<<(ostream&os, Int i) {
	os << i.s;
	return os;
}
int main() {
	int n; scanf("%d", &n);
	string s;
	rep(i, n) {
		string d; cin >> d;
		s += d;
	}
	for (Int i = 0;; ++i) {
		if ((int)s.find(i.s) == -1) {
			cout << i << endl;
			break;
		}
	}
}