Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  vector/*
    @uthor: Varun Mishra
    "varun21999" ->  Codechef, Codeforce, Hackerrank, Hackerearth;
*/
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int            long long int
#define ull            unsigned int
#define ld             long double
#define pb             push_back
#define pa             pair<int,int>
#define ppa            pair<pair<int,int>,int>
#define pap            pair<int,pair<int,int>>
#define v1d            vector<int>
#define v2d            vector<vector<int> >
#define vpa            vector<pair<int,int>>
#define M              1000000007
#define MN             LLONG_MIN
#define MX             LLONG_MAX
#define ff             first
#define ss             second
#define endl           "\n"
#define v1s            vector<string>
#define all(v)         v.begin(),v.end()
#define S(v)           sort(v.begin(),v.end())
#define RS(v)          sort(v.rbegin(),v.rend())
#define R(v)           reverse(v.begin(),v.end())
#define mxpq(T)        priority_queue <T>
#define mnpq(T)        priority_queue<T,vector<T>,greater<T>>
#define T              int tc;cin>>tc;while(tc--)
#define p2d(v)         for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)         for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)         for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define forIloop(i,n)  for(auto i=0;i<n;i++);
#define forDloop(i,n)  for(auto i=n-1;i>=0;i--);
#define qqq 400005
#define isEven(n)  (!n & 1);
const int MOD = 1e9 + 7;
// bool isEven(int n){
//     return (!(n & 1));
// }
// int popcount(int num){
//     num = num - ((num >> 1) & 0x55555555);
//     num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
//     return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
// }
// int powerOfTwo(int n){
//     return 1 << n;
// }

// int arr[1000001];
// bool temet = false;


void codeforce2(){
    int n; cin>>n;
    v1d arr(n);
    int left = 1, ans = 0;
    for (int i = 0; i < n; i++){
        cin>>arr[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        if(arr[i] == left){
            left++;
        }
        else
        {
            ans++;
        }
    }
    if(left == 0 && ans == 1){
        cout << "-1" << endl;
    }
    else if(ans<n){
        cout << ans << endl;
    }
    else{
        cout << "-1" << endl;
    }
    
    
}




int32_t main(){

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    /*#ifndef _DEBUG
     freopen("input.txt",  "r",  stdin);
     freopen("output.txt", "w", stdout);
    #endif*/
    //auto start = high_resolution_clock::now();

    // Lucario();
    //codeforceContest();
    //hackerEarth();
    //codeChef();
    codeforce2();

   /* auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    cout << "Time: "<<duration.count()<<endl;*/
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:45,
                 from a.cc:12:
/usr/include/c++/14/ext/typelist.h: In function 'int main()':
/usr/include/c++/14/ext/typelist.h:48:1: error: expected unqualified-id before 'namespace'
   48 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
      | ^~~~~~~~~
In file included from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/c++/14/tr1/type_traits:38:15: error: expected '=' before '__attribute__'
   38 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tr1/type_traits:38:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/ext/pb_ds/detail/type_utils.hpp:47,
                 from /usr/include/c++/14/ext/pb_ds/tag_and_trait.hpp:46,
                 from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:46:
/usr/include/c++/14/tr1/type_traits:38:14: error: expected ';' before '__attribute__'
   38 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/tr1/type_traits:39:1: error: expected primary-expression before '{' token
   39 | {
      | ^
/usr/include/c++/14/ext/pb_ds/detail/type_utils.hpp:51:1: error: 'namespace' definition is not allowed here
   51 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/tag_and_trait.hpp:52:1: error: 'namespace' definition is not allowed here
   52 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/hash_policy.hpp:48,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:45,
                 from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:47:
/usr/include/c++/14/ext/pb_ds/exception.hpp:48:1: error: 'namespace' definition is not allowed here
   48 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/hash_policy.hpp:50:
/usr/include/c++/14/ext/pb_ds/detail/hash_fn/mask_based_range_hashing.hpp:44:1: error: 'namespace' definition is not allowed here
   44 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/hash_policy.hpp:51:
/usr/include/c++/14/ext/pb_ds/detail/hash_fn/mod_based_range_hashing.hpp:44:1: error: 'namespace' definition is not allowed here
   44 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/hash_policy.hpp:52:
/usr/include/c++/14/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_size_base.hpp:44:1: error: 'namespace' definition is not allowed here
   44 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/hash_policy.hpp:54:1: error: 'namespace' definition is not allowed here
   54 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/list_update_policy.hpp:46,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:46:
/usr/include/c++/14/ext/pb_ds/detail/types_traits.hpp:50:1: error: 'namespace' definition is not allowed here
   50 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/list_update_policy.hpp:47:
/usr/include/c++/14/ext/pb_ds/detail/list_update_policy/lu_counter_metadata.hpp:41:1: error: 'namespace' definition is not allowed here
   41 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/list_update_policy.hpp:50:1: error: 'namespace' definition is not allowed here
   50 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:47:
/usr/include/c++/14/ext/pb_ds/detail/branch_policy/null_node_metadata.hpp:46:1: error: 'namespace' definition is not allowed here
   46 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/tree_policy.hpp:47,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:48:
/usr/include/c++/14/ext/pb_ds/detail/branch_policy/branch_policy.hpp:47:1: error: 'namespace' definition is not allowed here
   47 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/tree_policy.hpp:49:1: error: 'namespace' definition is not allowed here
   49 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/trie_policy.hpp:47,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:49:
/usr/include/c++/14/ext/pb_ds/detail/trie_policy/trie_policy_base.hpp:46:1: error: 'namespace' definition is not allowed here
   46 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/trie_policy.hpp:49:1: error: 'namespace' definition is not allowed here
   49 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/tr1/tuple:41:15: error: expected '=' before '__attribute__'
   41 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tr1/tuple:41:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/tr1/functional:40,
                 from /usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:51:
/usr/include/c++/14/tr1/tuple:41:14: error: expected ';' before '__attribute__'
   41 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/tr1/tuple:42:1: error: expected primary-expression before '{' token
   42 | {
      | ^
/usr/include/c++/14/tr1/functional_hash.h:35:15: error: expected '=' before '__attribute__'
   35 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tr1/functional_hash.h:35:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/tr1/functional:43:
/usr/include/c++/14/tr1/functional_hash.h:35:14: error: expected ';' before '__attribute__'
   35 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/tr1/functional_hash.h:36:1: error: expected primary-expression before '{' token
   36 | {
      | ^
/usr/include/c++/14/tr1/functional:47:15: error: expected '=' before '__attribute__'
   47 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tr1/functional:47:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/tr1/functional:47:14: error: expected ';' before '__attribute__'
   47 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/tr1/functional:48:1: error: expected primary-expression before '{' token
   48 | {
      | ^
/usr/include/c++/14/ext/pb_ds/detail/standard_policies.hpp:53:1: error: 'namespace' definition is not allowed here
   53 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/list_update_map_/lu_map_.hpp:43,
                 from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:66,
                 from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:48:
/usr/include/c++/14/ext/pb_ds/detail/cond_dealtor.hpp:46:1: error: 'namespace' definition is not allowed here
   46 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/list_update_map_/lu_map_.hpp:46:
/usr/include/c++/14/ext/pb_ds/detail/list_update_map_/entry_metadata_base.hpp:44:1: error: 'namespace' definition is not allowed here
   44 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/detail/list_update_map_/lu_map_.hpp:56:1: error: 'namespace' definition is not allowed here
   56 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp:43,
                 from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:67:
/usr/include/c++/14/ext/pb_ds/detail/eq_fn/eq_by_less.hpp:50:1: error: 'namespace' definition is not allowed here
   50 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp:55:1: error: 'namespace' definition is not allowed here
   55 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:68:
/usr/include/c++/14/ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp:47:1: error: 'namespace' definition is not allowed here
   47 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:69:
/usr/include/c++/14/ext/pb_ds/detail/splay_tree_/splay_tree_.hpp:76:1: error: 'namespace' definition is not allowed here
   76 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:70:
/usr/include/c++/14/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp:59:1: error: 'namespace' definition is not allowed here
   59 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp:46,
                 from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:71:
/usr/include/c++/14/ext/pb_ds/detail/hash_fn/ranged_hash_fn.hpp:49:1: error: 'namespace' definition is not allowed here
   49 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp:49:
/usr/include/c++/14/ext/pb_ds/detail/eq_fn/hash_eq_fn.hpp:49:1: error: 'namespace' definition is not allowed here
   49 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/include/c++/14/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp:58:1: error: 'namespace' definition is not allowed here
   58 | namespace __gnu_pbds
      | ^~~~~~~~~
In file included from /usr/include/c++/14/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp:42,
                 from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:72:
/usr/include/c++/14/ext/pb_ds/detail/hash_fn/ranged_probe_fn.hpp:48:1: error: 'namespace' definition is not allowed here
   48 | namespace __gnu_pbds
      | ^~~~~~~~~
/usr/i