// editor4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_REPORT_LEN 1024   // buffer for reading a line (safe upper limit)
#define MIN_VALID_LEN 5
#define MAX_VALID_LEN 100
#define MAX_KEY_LEN 20
#define MAX_N 1000

// remove trailing newline and carriage return
void strip_newline(char *s) {
    size_t L = strlen(s);
    while (L > 0 && (s[L-1] == '\n' || s[L-1] == '\r')) {
        s[--L] = '\0';
    }
}

void to_lower_inplace(char *s) {
    for (size_t i = 0; s[i]; ++i) s[i] = (char)tolower((unsigned char)s[i]);
}

int main(void) {
    int N;
    if (scanf("%d", &N) != 1) {
        printf("Invalid Input");
        return 0;
    }
    // consume rest of the line after the integer
    int ch;
    while ((ch = getchar()) != EOF && ch != '\n');

    if (N < 1 || N > MAX_N) {
        printf("Invalid Input");
        return 0;
    }

    char *reports = (char)malloc(sizeof(char) * N);
    if (!reports) {
        printf("Invalid Input");
        return 0;
    }

    for (int i = 0; i < N; ++i) {
        reports[i] = (char*)malloc(MAX_REPORT_LEN);
        if (!reports[i]) {
            printf("Invalid Input");
            // free previous
            for (int j = 0; j < i; ++j) free(reports[j]);
            free(reports);
            return 0;
        }
        if (fgets(reports[i], MAX_REPORT_LEN, stdin) == NULL) {
            printf("Invalid Input");
            for (int j = 0; j <= i; ++j) free(reports[j]);
            free(reports);
            return 0;
        }
        strip_newline(reports[i]);
        size_t len = strlen(reports[i]);
        if (len < MIN_VALID_LEN || len > MAX_VALID_LEN) {
            printf("Invalid Input");
            for (int j = 0; j <= i; ++j) free(reports[j]);
            free(reports);
            return 0;
        }
    }

    char keyword_buf[MAX_REPORT_LEN];
    if (fgets(keyword_buf, sizeof(keyword_buf), stdin) == NULL) {
        printf("Invalid Input");
        for (int i = 0; i < N; ++i) free(reports[i]);
        free(reports);
        return 0;
    }
    strip_newline(keyword_buf);
    size_t klen = strlen(keyword_buf);
    if (klen == 0 || klen > MAX_KEY_LEN) {
        printf("Invalid Input");
        for (int i = 0; i < N; ++i) free(reports[i]);
        free(reports);
        return 0;
    }

    // lowercase keyword
    to_lower_inplace(keyword_buf);

    int found_index = -1;
    // search from end; output index must be 1-based in original order
    for (int i = N - 1; i >= 0; --i) {
        // make lowercase copy of report for case-insensitive search
        char copy = (char)malloc(strlen(reports[i]) + 1);
        if (!copy) continue; // memory failure -> skip (shouldn't happen)
        strcpy(copy, reports[i]);
        to_lower_inplace(copy);
        if (strstr(copy, keyword_buf) != NULL) {
            found_index = i + 1; // 1-based
            free(copy);
            break;
        }
        free(copy);
    }

    if (found_index == -1) printf("Not Found");
    else printf("%d", found_index);

    for (int i = 0; i < N; ++i) free(reports[i]);
    free(reports);

return 0;
}