#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int binarySearch(int arr[], int left, int right, int x) {
    if (right < left)
        return -1;

    int mid = left + (right - left) / 2;

    if (arr[mid] == x)
        return mid;

    // Check if left half is sorted
    if (arr[left] <= arr[mid]) {
        if (x >= arr[left] && x <= arr[mid])
            return binarySearch(arr, left, mid - 1, x);
        return binarySearch(arr, mid + 1, right, x);
    }

    // Right half must be sorted
    if (x >= arr[mid] && x <= arr[right])
        return binarySearch(arr, mid + 1, right, x);
    return binarySearch(arr, left, mid - 1, x);
}

int isValidInteger(char *str) {
    // Check if a string represents a valid integer
    if (*str == '-' || *str == '+') str++;
    if (!*str) return 0;
    while (*str) {
        if (!isdigit(*str)) return 0;
        str++;
    }
    return 1;
}

int main() {
    int n;
    if (scanf("%d", &n) != 1 || n < 1 || n > 100000) {
        printf("Invalid input\n");
        return 0;
    }

    int arr = (int)malloc(n * sizeof(int));
    for (int i = 0; i < n; i++) {
        char temp[20];
        if (scanf("%s", temp) != 1 || !isValidInteger(temp)) {
            printf("Invalid input\n");
            free(arr);
            return 0;
        }
        arr[i] = atoi(temp);
    }

    char temp[20];
    if (scanf("%s", temp) != 1 || !isValidInteger(temp)) {
        printf("Invalid input\n");
        free(arr);
        return 0;
    }
    int x = atoi(temp);

    int result = binarySearch(arr, 0, n - 1, x);
    printf("%d\n", result);

    free(arr);
    return 0;
}