import java.util.Scanner; public class Main { public static void main(String[] a) { Scanner s=new Scanner(System.in); int i,P,E=1023; s.nextInt(); while(s.hasNext()){ for(i=0,P=0;i++<4;)P|=(int)Math.pow(2, s.nextInt()); E&=("NO".equals(s.next())?~P:P)&1023; } System.out.println((int)(Math.log(E)/Math.log(2))); } }