import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); if (N < 2||N > 6) System.exit(1); int A, B, C, D; String R; boolean[] ans = new boolean[10]; for (int i = 0; i < 10; i++) { ans[i] = true; } for (int i = 0; i < N; i++) { A = scan.nextInt(); B = scan.nextInt(); C = scan.nextInt(); D = scan.nextInt(); R = scan.next(); if (!match(A, B, C, D)||!(R.equals("YES")||R.equals("NO"))) System.exit(1); if (R.equals("YES")) { for (int j = 0; j < 10; j++) { if (!eq(j,A,B,C,D)) ans[j] = false; } } else { ans[A] = ans[B] = ans[C] = ans[D] = false; } } for (int i = 0; i < 10; i++) { if (ans[i]) { System.out.println(i); break; } } } public static boolean match (int... args) { for (int i : args) { if (i < 0 || i > 9) return false; } return true; } public static boolean eq (int x, int... args) { for (int i : args) { if (i == x) return true; } return false; } }