import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); StringBuilder head = new StringBuilder(); StringBuilder tail = new StringBuilder(); for (int i = 0; i < n; i++) { if (sc.next().charAt(0) == '0') { tail.append(sc.next()); } else { head.append(sc.next()); } } System.out.println(head.reverse().append(tail)); } }