#include <iostream>
#include <vector>
using namespace std;

const int MAX = 11000000;
bool isin[MAX];
int main() {
  int n; cin >> n;
  vector<int> d(n); for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < n; ++i) {
	int tmp = 0;
	for (int j = i; j < n; ++j) {
	  tmp *= 10;
	  tmp += d[j];
	  if (tmp >= MAX) break;
	  isin[tmp] = true;
	}
  }
  int res = 0;
  for (int i = 0; i < MAX; ++i) if (!isin[i]) {
	  res = i;
	  break;
	}
  cout << res << endl;
}

