#include <stdio.h>
#include <string.h>
#include <ctype.h>

int hasDigit(char str[]) {
    for (int i = 0; str[i] != '\0'; i++) {
        if (isdigit(str[i])) {
            return 1; // contains digit
        }
    }
    return 0;
}

int main() {
    int n;
    scanf("%d", &n);
    getchar(); // to consume newline after number

    char books[500][100]; 
    for (int i = 0; i < n; i++) {
        fgets(books[i], sizeof(books[i]), stdin);
        books[i][strcspn(books[i], "\n")] = '\0'; // remove newline

        if (hasDigit(books[i])) {
            printf("Invalid input");
            return 0;
        }
    }

    char query[100];
    fgets(query, sizeof(query), stdin);
    query[strcspn(query, "\n")] = '\0'; // remove newline

    if (hasDigit(query)) {
        printf("Invalid input");
        return 0;
    }

    // Search for the book
    for (int i = 0; i < n; i++) {
        if (strcmp(books[i], query) == 0) {
            printf("%d", i + 1); // 1-based index
            return 0;
        }
    }

    printf("");
    return 0;
}