N = int(input())
cards = [int(input()) for _ in range(N)]
dp = [0] * (N + 1)
dp[1] = cards[0]
for i in range(2, N + 1):
for j in range(i - 1, -1, -1):
new_number1 = int(str(dp[j]) + str(cards[i - 1]))
new_number2 = int(str(cards[i - 1]) + str(dp[j]))
dp[i] = max(dp[i], new_number1, new_number2)
print(dp[N])