#include <iostream>
#include <string>
#include <cctype>
using namespace std;

struct Node {
    string title;
    Node* next;
};

// Function to check if a title is valid (letters + spaces only)
bool isValidTitle(const string &s) {
    for (char c : s) {
        if (!(isalpha(c) || c == ' ')) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    if (!(cin >> n) || n < 1 || n > 500) {
        cout << "Invalid input";
        return 0;
    }
    cin.ignore(); // ignore newline after number

    Node* head = nullptr;
    Node* temp = nullptr;

    // Read titles
    for (int i = 0; i < n; i++) {
        string title;
        getline(cin, title);

        if (!isValidTitle(title)) {
            cout << "Invalid input";
            return 0;
        }

        Node* newNode = new Node;  // required usage
        newNode->title = title;
        newNode->next = nullptr;

        if (head == nullptr) {
            head = newNode;
            temp = newNode;
        } else {
            temp->next = newNode;
            temp = newNode;
        }
    }

    // Read search query
    string query;
    getline(cin, query);

    if (!isValidTitle(query)) {
        cout << "Invalid input";
        return 0;
    }

    // Search in linked list
    temp = head;
    int pos = 1;
    while (temp != nullptr) {
        if (temp->title == query) {
            cout << pos;
            return 0;
        }
        temp = temp->next;
        pos++;
    }

    cout << "Title not found";
    return 0;
}