#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAX 1000
#define LEN 200

// Function to convert string to lowercase
void toLower(char *str) {
        for (int i = 0; str[i]; i++) {
                    str[i] = tolower((unsigned char)str[i]);
        }
}

int main() {
        int n;
            if (scanf("%d", &n) != 1 || n < 1 || n > 1000) {
                //printf("Invalid Input\n");
                return 0;
            }
                getchar(); // remove newline
                
                char reports[MAX][LEN];
                    for (int i = 0; i < n; i++) {
                    fgets(reports[i], LEN, stdin);
                    reports[i][strcspn(reports[i], "\n")] = 0; // remove newline
                                            
                    int len = strlen(reports[i]);
                    
                    return 0;
                    }
                        }
                        
                    char keyword[LEN];
                    fgets(keyword, LEN, stdin);
                    keyword[strcspn(keyword, "\n")] = 0; // remove newline
                                    
                    // Convert keyword to lowercase
                    char keyLower[LEN];
                    strcpy(keyLower, keyword);
                    toLower(keyLower);
                                                    
                                                        
                    for (int i = n - 1; i >= 0; i--) {
                    char temp[LEN];
                    strcpy(temp, reports[i]);
                    toLower(temp);
                                                                                        
                    if (strstr(temp, keyLower) != NULL) {
                    printf("%d\n", i + 1); // 1-based index
                    return 0;
                            }
                    }
                                                            
                    printf("Not Found\n");
                return 0;
}