#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct Node {
    char title[101];
    struct Node* next;
} Node;
Node* createNode(char* title) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    strcpy(newNode->title, title);
    newNode->next = NULL;
    return newNode;
}
int isValid(char* str) {
    for (int i = 0; str[i]; i++) {
        if (!(isalpha(str[i]) || isspace(str[i]))) {
            return 0; 
        }
    }
    return 1; 
}

int searchTitle(Node* head, char* query) 
    int pos = 1;
    while (head) {
        if (strcmp(head->title, query) == 0)
            return pos;
        head = head->next;
        pos++;
    }
    return -1; 
}

int main() {
    int n;
    scanf("%d", &n);
    getchar(); 

    Node* head = NULL;
    Node* tail = NULL;

    char buffer[101];
    int validInput = 1;
    for (int i = 0; i < n; i++) {
        fgets(buffer, sizeof(buffer), stdin);
        buffer[strcspn(buffer, "\n")] = 0; 

        if (!isValid(buffer)) {
            validInput = 0;
        }

        Node* newNode = createNode(buffer);
        if (!head) {
            head = newNode;
            tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }
    fgets(buffer, sizeof(buffer), stdin);
    buffer[strcspn(buffer, "\n")] = 0;

    if (!isValid(buffer)) {
        validInput = 0;
    }

    if (!validInput) {
        printf("Invalid input\n");
        return 0;
    }
    int result = searchTitle(head, buffer);
    if (result != -1) {
        printf("%d\n", result);
    } else {
        printf("Title not found\n");
    }

    return 0;
}