import sys from itertools import permutations from functools import cmp_to_key def main(): N, K = map(int, sys.stdin.readline().split()) a = list(map(str, sys.stdin.readline().split())) # Custom comparator to sort the array def compare(x, y): if x + y > y + x: return -1 else: return 1 a_sorted = sorted(a, key=cmp_to_key(compare)) # Function to determine the minimal M where M! >= K def find_m(k): m = 1 fact = 1 while fact < k: m += 1 fact *= m return m M = find_m(K) if M > N: M = N # Split the sorted array into fixed and last M elements fixed = a_sorted[:N - M] last_m = a_sorted[N - M:] # Generate all unique permutations of last_m perms = set(permutations(last_m)) # Collect all possible concatenated strings numbers = set() for perm in perms: s = ''.join(fixed + list(perm)) numbers.add(s) # Convert to a sorted list in descending order sorted_numbers = sorted(numbers, reverse=True) # Output the top K numbers for num in sorted_numbers[:K]: print(num) if __name__ == '__main__': main()