#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

// Define the structure for a linked list node
struct Node {
    char title[100];
    struct Node* next;
};

// Function to create a new node
struct Node* newNode(const char* title) {
    struct Node* node = (struct Node*)malloc(sizeof(struct Node));
    if (node == NULL) {
        printf("Memory allocation failed!\n");
        exit(1);
    }
    strcpy(node->title, title);
    node->next = NULL;
    return node;
}

// Function to check if a string contains numeric characters
int has_numeric_chars(const char* str) {
    for (int i = 0; str[i] != '\0'; i++) {
        if (isdigit(str[i])) {
            return 1;
        }
    }
    return 0;
}

// Function to insert a new node at the end of the list
void insert_at_end(struct Node** head_ref, const char* title) {
    struct Node* new_node = newNode(title);
    if (*head_ref == NULL) {
        *head_ref = new_node;
        return;
    }
    struct Node* last = *head_ref;
    while (last->next != NULL) {
        last = last->next;
    }
    last->next = new_node;
}

// Function to search for a title in the linked list
void search_title(struct Node* head, const char* search_query) {
    // Search query validation must be done before searching
    if (has_numeric_chars(search_query)) {
        printf("Invalid input\n");
        return;
    }
    
    struct Node* current = head;
    int position = 1;
    while (current != NULL) {
        if (strcmp(current->title, search_query) == 0) {
            printf("%d\n", position);
            return;
        }
        current = current->next;
        position++;
    }
    printf("Title not found\n");
}

// Main function
int main() {
    int n;
    scanf("%d", &n);
    getchar(); // Consume the trailing newline character

    struct Node* head = NULL;
    char title[100];

    // Read book titles and build the linked list with validation
    for (int i = 0; i < n; i++) {
        fgets(title, sizeof(title), stdin);
        title[strcspn(title, "\n")] = 0;

        if (has_numeric_chars(title)) {
            printf("Invalid input\n");
            // Free any allocated memory before exiting
            struct Node* temp;
            while (head != NULL) {
                temp = head;
                head = head->next;
                free(temp);
            }
            return 0;
        }
        insert_at_end(&head, title);
    }
    
    // Read the title to be searched
    fgets(title, sizeof(title), stdin);
    title[strcspn(title, "\n")] = 0;

    // Search for the title and print the result
    search_title(head, title);
    
    // Free the allocated memory
    struct Node* temp;
    while (head != NULL) {
        temp = head;
        head = head->