#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define ll long long int
#define t() int test;cin>>test;while(test–)
using namespace std;
int location(int arr[], int n, int pivot, int key){
int s1=0,e1=pivot,s2=pivot,e2=n-1;
while(s1<=e1){
int mid=(s1+e1)/2;
if (arr[mid]==key)
{
return mid;
}
else if(arr[mid]<key){
s1=mid;
}
else e1=mid;
}
while(s2<=e2){
int mid=(s2+e2)/2;
if (arr[mid]==key)
{
return mid;
}
else if(arr[mid]<key){
s2=mid;
}
else e2=mid;
}
return -1;
}
int findpivot(int arr[], int n){
int s=0, e=n-1, result=0;
while(s<=e){
int mid=(s+e)/2;
if(arr[mid]>=arr[e]){
s=mid;
result=mid;
}
else{
e=mid;
result=mid;
}
}
return result;
}
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int key;
cin>>key;
int pivot=findpivot(arr, n);
cout<<location(arr, n, pivot, key);
return 0;
}