import java.io.*;
import java.util.*;

public class program_md implements Runnable {
	private Scanner in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		in = new Scanner(new FileReader("program.in"));
		out = new PrintWriter("program.out");
		int n = in.nextInt();
		boolean caseSensitive = "yes".equals(in.next());
		boolean digitFirst = "yes".equals(in.next());
		HashSet<String> keywords = new HashSet<String>();
		for (int i = 0; i < n; i++) {
			String key = in.next();
			if (!caseSensitive)
				key = key.toLowerCase();
			keywords.add(key);
		}
		in.useDelimiter("[^a-zA-Z0-9_]+");
		HashMap<String, Integer> count = new HashMap<String, Integer>();
		HashMap<String, Integer> first = new HashMap<String, Integer>();
		while (in.hasNext()) {
			String s = in.next();
			if (!caseSensitive)
				s = s.toLowerCase();
			if (keywords.contains(s))
				continue;
			boolean allDigits = true;
			for (int i = 0; i < s.length(); i++) {
				if (!Character.isDigit(s.charAt(i))) {
					allDigits = false;
					break;
				}
			}
			if (allDigits)
				continue;
			if (!digitFirst && Character.isDigit(s.charAt(0)))
				continue;
			int c = 0;
			if (count.containsKey(s)) {
				c = count.get(s);
			}
			count.put(s, c + 1);
			if (!first.containsKey(s)) {
				first.put(s, first.size());
			}
		}
		int bc = -1;
		int bf = -1;
		String ans = "$";
		for (String s : count.keySet()) {
			int c = count.get(s);
			int f = first.get(s);
			if ((c > bc) || ((c == bc) && (f < bf))) {
				bc = c;
				bf = f;
				ans = s;
			}
		}
		out.println(ans);
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(new program_md()).start();
	}
}
