b=int(input()) a=int(input()) c=[int(i) for i in input().split()] c.sort() for j,i in enumerate(c): b-=i if b<=0: print(i)