def quick_sort(a, l, r): if l >= r: return a first = l last = r m = a[l] while first < last: if first < last and a[last] <= m: last-=1 a[first] = a[last] if first < last and a[first] >= m: first+=1 a[last] = a[first] a[first] = m quick_sort(a, l, first-1) quick_sort(a, first+1, r) return a if l >= r: return a[l:r] def bigrich(l, n,m): res=quick_sort(l, 0, n-1) arr=[] for i in res: arr.append(str(i)) res = arr if m > n: print(' '.join(res)) else: print(' '.join(res[:m])) while True: try: n, m = map(int, input().split()) l = list(map(int, input().split())) bigrich(l, n, m) except: break