import java.util.Scanner; import java.util.List; import java.util.ArrayList; class Main { public static void main(String[] args) { No0021 no = new No0021(); System.out.println(no.result()); } } class No0021 { public final int MAX_NUM = 9; public final int COL_NUM = 4; public final String STR_YES = "YES"; public final String STR_NO = "NO"; private int n; private List boolList; private String result; public No0021() { Scanner sc = new Scanner(System.in); this.n = sc.nextInt(); this.boolList = new ArrayList<>(MAX_NUM); for (int i = 0; i < MAX_NUM; i++) { this.boolList.add(true); } for (int i = 0; i < this.n; i++) { List valList = new ArrayList<>(COL_NUM); for (int j = 0; j < COL_NUM; j++) { valList.add(sc.nextInt()); } String ret = sc.next(); if (STR_NO.equals(ret)) { for (Integer val : valList) { if (!boolList.get(val)) { this.boolList.set(val, false); } } } } for (int i = 0; i < this.boolList.size(); i++) { if (this.boolList.get(i)) { this.result = String.valueOf(i); } } } public String result() { return this.result; } }