public static void main(String[]args){
		String in="data/p3.in", out="data/p3.out";
		try(BufferedReader br=(new BufferedReader(new InputStreamReader(new FileInputStream(new File(in)))));
				PrintWriter bw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(out)))));) {
			String line;
			List<String> s=new ArrayList<>();
			while ((line=br.readLine())!=null) {
				s.add(line.trim());
			}
			boolean[]v=new boolean[s.size()];
			int state=0;
			while (!v[state]) {
				v[state]=true;
				if (s.get(state).indexOf("NEXT")!=-1) ++state;
				else state=Integer.parseInt(s.get(state).split("\\s+")[1])-1;
			}
			for (int i=0;i<s.size();++i) {
				if (!v[i]) bw.println((i+1));
			}
		} catch(IOException e) {
			e.printStackTrace();
		}
	}