#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef struct Node {
    char *title;
    struct Node *next;
} Node;

Node* newNode(const char* t) {
    Node *n = malloc(sizeof(Node));
    if (!n) exit(EXIT_FAILURE);
    n->title = strdup(t);
    if (!n->title) exit(EXIT_FAILURE);
    n->next = NULL;
    return n;
}

int is_valid(const char* s) {
    for (const char* p = s; *p; p++) {
        if (!isalpha((unsigned char)*p) && *p != ' ')
            return 0;
    }
    return 1;
}

int main(void) {
    int n;
    if (scanf("%d%*c", &n) != 1 || n < 1 || n > 500) {
        return 0; // or print error
    }

    char buffer[1001];
    Node *head = NULL, *tail = NULL;

    for (int i = 0; i < n; i++) {
        if (!fgets(buffer, sizeof buffer, stdin)) return 0;
        buffer[strcspn(buffer, "\n")] = '\0';

        if (!is_valid(buffer)) {
            printf("Invalid input\n");
            return 0;
        }

        Node *nd = newNode(buffer);
        if (!head) head = tail = nd;
        else {
            tail->next = nd;
            tail = nd;
        }
    }

    if (!fgets(buffer, sizeof buffer, stdin)) return 0;
    buffer[strcspn(buffer, "\n")] = '\0';

    if (!is_valid(buffer)) {
        printf("Invalid input\n");
        return 0;
    }

    Node *cur = head;
    int pos = 1;
    while (cur) {
        if (strcmp(cur->title, buffer) == 0) {
            printf("%d\n", pos);
            return 0;
        }
        cur = cur->next;
        pos++;
    }

    printf("Title not found\n");
    return 0;
}