#include "iostream"
#include "random"
#include "ctime"
#include "chrono"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"

using namespace std;


int main() {
	int N;
	cin >> N;
	string s;
	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		s.push_back(c);
	}
	for (int i = 0; i <= 1000000; i++) {
		if (s.find(to_string(i))>=s.size()) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}
