#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>

using namespace std;

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	bool used[10000];
	memset(used, 0, sizeof(used));
	int n;
	cin >> n;
	vector<char> s(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> s[i];
	}
	for (int i = 0; i < n; ++i)
	{
		int digit = 0;
		for (int j = 0; j < 4 && i + j < n; ++j)
		{
			digit = digit * 10 + s[i + j] - '0';
			used[digit] = true;
		}
	}
	int pos = 0;
	while (true)
	{
		if (used[pos] == 0)
		{
			cout << pos << endl;
			return;
		}
		++pos;
	}
}

int main()
{
	solve();
	return(0);
}