import java.util.ArrayDeque; import java.util.Arrays; import java.util.Queue; import java.util.Scanner; public class Main { private int n; private int how_yes; private int[] num; private boolean[] bad; Main(){ num = new int[10]; bad = new boolean[10]; } public void setN(int n){ this.n = n; } public void plusHow_yes(){ this.how_yes++; } public void yes(int[] k){ for(int i = 0;i < 4;i++){ num[k[i]]++; } } public void no(int[] k){ for(int i = 0;i < 4;i++){ bad[k[i]] = true; } } public int ans(){ for(int i = 0;i < 10;i++){ if(bad[i]) continue; if(num[i] == how_yes) return i; } return -1; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); Main m = new Main(); int n = sc.nextInt(); m.setN(n); String str; int[] k = new int[5]; for(int i = 0;i < n;i++){ for(int j = 0;j < 4;j++){ k[j] = sc.nextInt(); } str = sc.next(); if(str.equals("YES")){ m.plusHow_yes(); m.yes(k); }else{ m.no(k); } } System.out.println(m.ans()); } }