l = int(input()) n = int(input()) w = input().split() w = list(map(int, w )) i = -1 while l>0: i += 1 l = l-min(w) w.remove(min(w)) print(i)