import heapq class PriorityString: def __init__(self, s): self.s = s def __lt__(self, other): return (self.s + other.s) < (other.s + self.s) n = int(input()) strings = [input().strip() for _ in range(n)] heap = [] for s in strings: if s: heapq.heappush(heap, PriorityString(s)) result = [] while heap: current = heapq.heappop(heap) result.append(current.s[0]) remaining = current.s[1:] if remaining: heapq.heappush(heap, PriorityString(remaining)) print(''.join(result))