import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); ArrayList> chars = new ArrayList>(); for(int i = 0; i < N; i++){ final char[] input = sc.next().toCharArray(); LinkedList list = new LinkedList(); for(final char c : input){ list.add(c); } chars.add(list); } StringBuilder sb = new StringBuilder(); while(true){ char min = '\0'; int min_pos = -1; for(int i = 0; i < N; i++){ final LinkedList list = chars.get(i); if(list.isEmpty()){ continue; } if(min_pos < 0 || list.peek() < min){ min = list.peek(); min_pos = i; }else if(list.peek() == min){ final int list_prev = list.size() == 1 ? Integer.MAX_VALUE : list.get(1); final int min_pos_prev = chars.get(min_pos).size() == 1 ? Integer.MAX_VALUE : chars.get(min_pos).get(1); if(list_prev < min_pos_prev){ min_pos = i; } } } if(min_pos < 0){ break; } sb.append(chars.get(min_pos).poll()); } System.out.println(sb.toString()); } }