def main():
    input()
    p = list(input().split())
    p.sort(key=lambda x: -int((x * 4)[:4]))
    print(''.join(p))


if __name__ == '__main__':
    main()

def main():
    input()
    p = list(input().split())
    p.sort(key=lambda x: -int((x * 4)[:4]))
    print(''.join(p))


if __name__ == '__main__':
    main()
