stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int n, a[N];

vector<int> occ[N]; // occurrence vectors

int main() {

  	cin >> n;

  	for (int i = 0; i < n; ++i) {

      	cin >> a[i];

    	occ[a[i]].push_back(i);

    }

  	int prev = -1, taken = 0;

  	for (int val = 1; val <= n; ++val) {

  		bool found = false;

    	for (auto idx: occ[val]) {

        	if (idx > prev) {

             	prev = idx; 

              	taken++;

              	found = true;

             	break;

            }

        }

        if (!found)

        	break;

    }

  	if (taken == 0)

      	cout << -1 << endl;

	else

  		cout << n - taken << endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.47322857610556x):
#include<bits/stdc++.h>

using namespace std;

int main()

{

	int n;

	cin>>n;

	int a[n];

	for(int i=0;i<n;i++)

	cin>>a[i];

	int ans=0;

	for(int i=0;i<n;i++)

	{

		if(a[i]==ans+1)

		{

			ans++;

		}

	}

	if(ans==0)

	cout<<-1<<endl;

	else

	cout<<n-ans<<endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int n, a[N];

vector<int> occ[N]; // occurrence vectors

int main() {

  	cin >> n;

  	for (int i = 0; i < n; ++i) {

      	cin >> a[i];

    	occ[a[i]].push_back(i);

    }

  	int prev = -1, taken = 0;

  	for (int val = 1; val <= n; ++val) {

  		bool found = false;

    	for (auto idx: occ[val]) {

        	if (idx > prev) {

             	prev = idx; 

              	taken++;

              	found = true;

             	break;

            }

        }

        if (!found)

        	break;

    }

  	if (taken == 0)

      	cout << -1 << endl;

	else

  		cout << n - taken << endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.394709938118931x):
#include <bits/stdc++.h>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstring>

#include <chrono>

#include <complex>

#define endl "\n"

#define ll long long int

#define vi vector<int>

#define vll vector<ll>

#define vvi vector < vi >

#define pii pair<int,int>

#define pll pair<long long, long long>

#define mod 1000000007

#define inf 1000000000000000001;

#define all(c) c.begin(),c.end()

#define mp(x,y) make_pair(x,y)

#define mem(a,val) memset(a,val,sizeof(a))

#define eb emplace_back

#define f first

#define s second



using namespace std;

int main()

{

	std::ios::sync_with_stdio(false);

  int n;

    cin >> n;

    int cur = 1;

    int brk = n;

    for(int i = 0; i < n; ++i)

    {

        int x;

        cin >> x;

        if(x == cur) {

            brk--;

            ++cur;

        }

    }

    if(brk == n) cout << -1 << '\n';

    else cout << brk << '\n';

    return 0;



}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int n, a[N];

vector<int> occ[N]; // occurrence vectors

int main() {

  	cin >> n;

  	for (int i = 0; i < n; ++i) {

      	cin >> a[i];

    	occ[a[i]].push_back(i);

    }

  	int prev = -1, taken = 0;

  	for (int val = 1; val <= n; ++val) {

  		bool found = false;

    	for (auto idx: occ[val]) {

        	if (idx > prev) {

             	prev = idx; 

              	taken++;

              	found = true;

             	break;

            }

        }

        if (!found)

        	break;

    }

  	if (taken == 0)

      	cout << -1 << endl;

	else

  		cout << n - taken << endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.332307420716884x):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define Fast() ios_base::sync_with_stdio(false);cin.tie(NULL);

int main()

{

     Fast();

     ll n,t,x,y,i,j,k,mini=LONG_LONG_MAX,maxi=LONG_LONG_MIN,flag =0 ,sum=0,mul=1;

     vector<ll>vi;

     vector<ll> :: iterator it;

     string s,s1="";

     cin>>n;

     for(i = 0 ;i<n; i++)

     {

         cin>>x;

         vi.push_back(x);

     }



     for(i = 0 ;i<n ;i++  )

     {

         if(vi[i]==sum+1)

            sum++;

     }

     if(sum == 0)

        cout<<-1<<endl;

     else

     cout<<n-sum<<endl;





}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int n, a[N];

vector<int> occ[N]; // occurrence vectors

int main() {

  	cin >> n;

  	for (int i = 0; i < n; ++i) {

      	cin >> a[i];

    	occ[a[i]].push_back(i);

    }

  	int prev = -1, taken = 0;

  	for (int val = 1; val <= n; ++val) {

  		bool found = false;

    	for (auto idx: occ[val]) {

        	if (idx > prev) {

             	prev = idx; 

              	taken++;

              	found = true;

             	break;

            }

        }

        if (!found)

        	break;

    }

  	if (taken == 0)

      	cout << -1 << endl;

	else

  		cout << n - taken << endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.47849573050402x):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n,i,j,k,l,x,c=0;

    cin>>n;

    int ar[n];

    for(i=0;i<n;i++)

    {

        cin>>ar[i];

        if(ar[i]==1)

        {

            c=1;

        }

    }

    if(c==0)

    {

        cout<<"-1"<<endl;

        return 0;

    }

    else

    {

        x=1;

        for(i=0;i<n;i++)

        {

            if(ar[i]==x)

                x++;

        }

        cout<<n-x+1<<endl;

    }

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int n, a[N];

vector<int> occ[N]; // occurrence vectors

int main() {

  	cin >> n;

  	for (int i = 0; i < n; ++i) {

      	cin >> a[i];

    	occ[a[i]].push_back(i);

    }

  	int prev = -1, taken = 0;

  	for (int val = 1; val <= n; ++val) {

  		bool found = false;

    	for (auto idx: occ[val]) {

        	if (idx > prev) {

             	prev = idx; 

              	taken++;

              	found = true;

             	break;

            }

        }

        if (!found)

        	break;

    }

  	if (taken == 0)

      	cout << -1 << endl;

	else

  		cout << n - taken << endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.391620789358231x):
#include <bits/stdc++.h>



using namespace std;



#define fi first

#define se second

#define eb emplace_back

#define mt make_tuple

#define all(x) (x).begin(), (x).end() 

#define MOD 1000000007



typedef long long ll;

typedef pair <int, int> ii;

typedef pair <ll, ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef long double ld;



const ll INF=LLONG_MAX;

const int mxn=2e5+5;

int a[mxn];



int main()

{

    ios_base::sync_with_stdio(0); cin.tie(0);

    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

	int n; cin >> n;

	int look=1;

	for(int i=0; i<n; i++){

		cin >> a[i];

		if(a[i]==look){

			look++;

		}

	}

	if(look==1){

		cout << -1 << endl;

	}else{

		cout << n-look+1 << endl;

	}

}

	

// READ & UNDERSTAND

// ll, int overflow, array bounds, memset(0)

// special cases (n=1?), n+1 (1-index)

// do smth instead of nothing & stay organized

// WRITE STUFF DOWN
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int n, a[N];

vector<int> occ[N]; // occurrence vectors

int main() {

  	cin >> n;

  	for (int i = 0; i < n; ++i) {

      	cin >> a[i];

    	occ[a[i]].push_back(i);

    }

  	int prev = -1, taken = 0;

  	for (int val = 1; val <= n; ++val) {

  		bool found = false;

    	for (auto idx: occ[val]) {

        	if (idx > prev) {

             	prev = idx; 

              	taken++;

              	found = true;

             	break;

            }

        }

        if (!found)

        	break;

    }

  	if (taken == 0)

      	cout << -1 << endl;

	else

  		cout << n - taken << endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.3819920752127794x):
#pragma GCC optimize("O2")

#include <bits/stdc++.h>

using namespace std;

#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)

//#define MULTI_TEST

//#define GOOGLE

#ifdef LOCAL

#include "debugger.h"

#else

#define db(...)

#endif

#define ll long long

#define v32 vector<int>

#define v64 vector<ll>

#define s32 set<int>

#define s64 set<ll>

#define p32 pair<int, int>

#define p64 pair<ll, ll>

#define sz(v) (ll)(v).size()

#define fi first

#define se second

#define ln '\n'

const ll MOD = 1e9 + 7;

inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }

inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }



void solve(int tc)

{

	int n;

	cin >> n;

	v32 arr(n, 0);

	for (int i = 0; i < n; i++)

		cin >> arr[i];

	int cnt = 0, req = 1;

	for (int i = 1; i < n + 1; i++)

	{

		if (arr[i - 1] == req)

		{

			req++;

			cnt++;

		}

	}

	if (cnt == 0)

		cnt = n + 1;

	cout << (n - cnt) << ln;

	return;

}



int main()

{

#ifndef LOCAL

	FASTIO;

#endif

	int t = 1;

#ifdef LOCAL

	clock_t start, stop;

	start = clock();

#endif

#ifdef MULTI_TEST

	cin >> t;

#endif

	for (int tc = 1; tc < t + 1; tc++)

	{

#ifdef GOOGLE

		cout << "Case #" << tc << ": ";

#endif

		solve(tc);

	}

#ifdef LOCAL

	stop = clock();

	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;

#endif

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int n, a[N];

vector<int> occ[N]; // occurrence vectors

int main() {

  	cin >> n;

  	for (int i = 0; i < n; ++i) {

      	cin >> a[i];

    	occ[a[i]].push_back(i);

    }

  	int prev = -1, taken = 0;

  	for (int val = 1; val <= n; ++val) {

  		bool found = false;

    	for (auto idx: occ[val]) {

        	if (idx > prev) {

             	prev = idx; 

              	taken++;

              	found = true;

             	break;

            }

        }

        if (!found)

        	break;

    }

  	if (taken == 0)

      	cout << -1 << endl;

	else

  		cout << n - taken << endl;

 	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.3973856349362785x):
#include <bits/stdc++.h>

#define lli long long int

using namespace std;



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	int a, arr[20002]; cin>>a;

	

	int num=0, cur=1;

	for(int i=0; i<a; i++){

		int b; cin>>b;

		if(b==cur){

			num++;

			cur++;

		}

	}

	

	if(num) cout<<a-num<<endl;

	else cout<<"-1"<<endl;



	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>



using namespace std;



int main(int argc, const char *argv[]) {

  int n;

  cin >> n;



  int cur = 1, ans = 0, found = false;

  for (int i = 0; i < n; i++) {

    int a;

    cin >> a;

    if (a == cur) {

      found = true;

      cur++;

    } else {

      ans++;

    }

  }



  cout << (found ? ans : -1) << '\n';



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.512920947784067x):
#include <cstdio>



int main(int argc, const char *argv[]) {

  int n;

  scanf("%d", &n);



  int a[300000];

  for (int i = 0; i < n; i++) {

    scanf("%d", &a[i]);

  }



  int ans = 0, cur = 1;

  for (int i = 0; i < n; i++) {

    if (a[i] != cur) {

      ans++;

    } else {

      cur++;

    }

  }



  printf("%d\n", ans == n ? -1 : ans);

}
// Slower C++ solution:
#include <algorithm>

#include <cmath>

#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main(int argc, const char *argv[]) {

  int n;

  cin >> n;

  vector<int> va(n);

  bool exists = false;

  for (auto &a : va) {

    cin >> a;

    if (a == 1) {

      exists = true;

    }

  }



  if (!exists) {

    cout << -1 << '\n';

    return 0;

  }



  int cur = 1, ans = 0;

  for (auto &a : va) {

    if (a != cur) {

      ans++;

    } else {

      cur++;

    }

  }



  cout << ans << '\n';

}

// Faster C++ solution for the same problem (measured speedup: 4.520473985294564x):
#include <cstdio>



int main(int argc, const char *argv[]) {

  int n;

  scanf("%d", &n);



  int a[300000];

  for (int i = 0; i < n; i++) {

    scanf("%d", &a[i]);

  }



  int ans = 0, cur = 1;

  for (int i = 0; i < n; i++) {

    if (a[i] != cur) {

      ans++;

    } else {

      cur++;

    }

  }



  printf("%d\n", ans == n ? -1 : ans);

}
// Slower C++ solution:
#include <iostream>



using namespace std;



int main(int argc, const char *argv[]) {

  int n, a, cur = 1, ans = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {

    cin >> a;

    if (a != cur) {

      ans++;

    } else {

      cur++;

    }

  }



  cout << (ans == n ? -1 : ans) << '\n';

}


// Faster C++ solution for the same problem (measured speedup: 4.511886155709827x):
#include <cstdio>



int main(int argc, const char *argv[]) {

  int n;

  scanf("%d", &n);



  int a[300000];

  for (int i = 0; i < n; i++) {

    scanf("%d", &a[i]);

  }



  int ans = 0, cur = 1;

  for (int i = 0; i < n; i++) {

    if (a[i] != cur) {

      ans++;

    } else {

      cur++;

    }

  }



  printf("%d\n", ans == n ? -1 : ans);

}
// Slower C++ solution:
#include <iostream>

#include <vector>



using namespace std;



int main(int argc, const char *argv[]) {

  int n;

  cin >> n;

  vector<int> va(n);

  for (auto &a : va) {

    cin >> a;

  }



  int ans = 0, cur = 1;

  for (auto &a : va) {

    if (a != cur) {

      ans++;

    } else {

      cur++;

    }

  }



  cout << (ans == va.size() ? -1 : ans) << '\n';

}

// Faster C++ solution for the same problem (measured speedup: 4.556260085833588x):
#include <cstdio>



int main(int argc, const char *argv[]) {

  int n;

  scanf("%d", &n);



  int a[300000];

  for (int i = 0; i < n; i++) {

    scanf("%d", &a[i]);

  }



  int ans = 0, cur = 1;

  for (int i = 0; i < n; i++) {

    if (a[i] != cur) {

      ans++;

    } else {

      cur++;

    }

  }



  printf("%d\n", ans == n ? -1 : ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)

#define rep(i,n) REP(i,0,n)

#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)

#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;

typedef unsigned long long ull;



int dp[200005];



int main(){

  int N;

  cin >> N;

  vector<int> v;

  rep(i,N){

    int a;

    cin >> a;

    v.push_back(a);

  }



  rep(i,200005) dp[i] = -1;



  rep(i,N){

    if(dp[v[i]] != -1) continue;

    if(v[i] == 1){

      dp[1] = i;

    }else{

      if(dp[v[i]-1] != -1){

        dp[v[i]] = i;

      }

    }

  }



  int mx = -1;

  REP(i,1,N+1){

    if(dp[i] != -1) mx = max(mx, i);

  }



  if(mx == -1) cout << -1 << endl;

  else cout << N - mx << endl;

  

  return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.8080345705975691x):
#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)

#define rep(i,n) REP(i,0,n)

#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)

#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;

typedef unsigned long long ull;





int main(){

  int N;

  cin >> N;

  vector<int> v;

  rep(i,N){

    int a;

    cin >> a;

    v.push_back(a);

  }



  int cnt = 0;

  rep(i,N){

    if(v[i] == cnt+1){

      cnt++;

    }

  }



  if(cnt == 0) cout << -1 << endl;

  else cout << N - cnt << endl;

  

  return 0;

}
// Slower C++ solution:
#include <iostream>



using namespace std;

int main(){

	ios::sync_with_stdio(0), cin.tie(0);

	int n, a, breaks=0, i=1, limit;

	cin >> n;

	limit = n - 1;

	while(n){

		cin >> a;

		if(a != i){

			if(breaks < limit){

				breaks++;

			}

			else{

				cout << -1 << '\n';

				return 0;

			}

		}

		else{

			i++;

		}

		n--;

	}

	cout << breaks << '\n';

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.344817187459874x):
#include<cstdio>



int main()

{

	int n; scanf("%d", &n);

	int now = 0;

	

	for(int i = 0; i < n; i++){

		int inp; scanf("%d", &inp);

		if(inp == now + 1) now++;

	}

	if(now == 0) printf("-1\n");

	else printf("%d\n", n - now);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main()

{

    int n,f=1;

    cin>>n;

    int x[n];

    for(int i=0;i<n;i++)cin>>x[i];

    for(int i=0;i<n;i++)

    {

        if(x[i]==f)f++;



    }

    if(f==1)cout<<"-1"<<endl;

    else cout<<n-f+1<<endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.274801131786721x):
#include<cstdio>



int main()

{

	int n; scanf("%d", &n);

	int now = 0;

	

	for(int i = 0; i < n; i++){

		int inp; scanf("%d", &inp);

		if(inp == now + 1) now++;

	}

	if(now == 0) printf("-1\n");

	else printf("%d\n", n - now);

}
// Slower C++ solution:
////////////////////////// Author

////////////////////////// Nasim Hossain Rabbi

////////////////////////// JU-CSE28

////////////////////////// CF - imnasim3.1415

////////////////////////// UVA - imnasim3.1415

////////////////////////// Mail - imnasim3.1415@gmail.com

#include<bits/stdc++.h>

using namespace std;

#define E end()

#define B begin()

#define sz size()

#define EM empty()

#define clr clear()

#define sqr(a) (a*a)

#define mk make_pair

#define pb push_back

string en="\n";

string t="hello";

#define rep(i,n) for(i=0;i<n;i++)

#define Rep(i,n) for(i=1;i<=n;i++)

#define per(i,n) for(i=n-1;i>=0;i--)

#define peR(i,n) for(i=n;i>0;i--)

#define mem(a,b) memset(a,b,sizeof(a))

#define all(cont) cont.begin(),cont.end()

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)

#define pi 3.1415926535897932384626433832795

#define vi vector<long long>

#define vs vector<string>

#define vp(vi,x) cin>>x; vi.pb(x);

#define srch(a,x) binary_search(all(a),x)

#define LB(a,x) (lower_bound(all(a),x)-a.B)

#define UB(a,x) (upper_bound(all(a),x)-a.B)

typedef long long LL;

typedef unsigned long long ULL;

bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}

bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}

bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}

int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}

template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

int main()

{

//    fast;

    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;

    while(cin>>n)

    {

        vi a;

        rep(i,n)

        {

            vp(a,x);

        }

        s=0;

        c=1;

        rep(i,n)

        {

            if(a[i]==c)

            {

                c++;

            }

            else s++;

        }

        if(s==n) cout<<-1<<en;

        else

        cout<<s<<en;

    }

}




// Faster C++ solution for the same problem (measured speedup: 5.413187188233662x):
#include<cstdio>



int main()

{

	int n; scanf("%d", &n);

	int now = 0;

	

	for(int i = 0; i < n; i++){

		int inp; scanf("%d", &inp);

		if(inp == now + 1) now++;

	}

	if(now == 0) printf("-1\n");

	else printf("%d\n", n - now);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main( )

{

    int n, i, j, k = 1;

    cin >> n;

    for (i = 1; i <= n; i++) {

        cin >> j;

        if (j == k) {

            k++;

        }

    }

    k--;

    if (k == 0) {

        cout << "-1\n";

    }

    else {

        cout << (n - k) << '\n';

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.26434510784954x):
#include<cstdio>



int main()

{

	int n; scanf("%d", &n);

	int now = 0;

	

	for(int i = 0; i < n; i++){

		int inp; scanf("%d", &inp);

		if(inp == now + 1) now++;

	}

	if(now == 0) printf("-1\n");

	else printf("%d\n", n - now);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main()

{

ll a,b,c,d=0,e=1,i,j,k,l;

 cin>>a;

  vector<ll>v;

  for(i=1;i<=a;i++)

  {

  cin>>b;

  v.push_back(b);

  }

  for(i=0;i<a;i++)

  {

  if(v[i]==e){e++;d++;}

  }

 if(d==0)cout<<"-1\n";

 else {

   cout<<a-d<<endl;

      }

}

// Faster C++ solution for the same problem (measured speedup: 5.322610857449482x):
#include<cstdio>



int main()

{

	int n; scanf("%d", &n);

	int now = 0;

	

	for(int i = 0; i < n; i++){

		int inp; scanf("%d", &inp);

		if(inp == now + 1) now++;

	}

	if(now == 0) printf("-1\n");

	else printf("%d\n", n - now);

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

typedef long long ll ;

const int N =  1e5 ;

int main()

{

    ll n ;

    cin >> n ;

    int arr[n];

    int x=0 ;

    for(int i = 0 ; i < n ; i++)

    {

        cin >> arr[i] ;

        if(arr[i]==x+1)

        {

            x++;

        }

    }

    if(x==0)

    {

        cout << -1 ;

    }

    else cout <<n-x;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.282967303283585x):
#include<cstdio>



int main()

{

	int n; scanf("%d", &n);

	int now = 0;

	

	for(int i = 0; i < n; i++){

		int inp; scanf("%d", &inp);

		if(inp == now + 1) now++;

	}

	if(now == 0) printf("-1\n");

	else printf("%d\n", n - now);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long



 

using namespace std;

int main()

{

    ll n, temp;

    cin>>n;

    ll j=1,ans=0;

    for(int i=1;i<=n;i++)

    {

        cin>>temp;

        if(temp==j)

        {   j++;

            ans++;

        }

    }

    if(ans==0)

        cout<<"-1\n";

    else

        cout<<n-ans<<"\n";

    

}

// Faster C++ solution for the same problem (measured speedup: 5.266073823728916x):
#include<cstdio>



int main()

{

	int n; scanf("%d", &n);

	int now = 0;

	

	for(int i = 0; i < n; i++){

		int inp; scanf("%d", &inp);

		if(inp == now + 1) now++;

	}

	if(now == 0) printf("-1\n");

	else printf("%d\n", n - now);

}