L = int(input()) N = int(input()) W = sorted(map(int, input().split())) ans = 0 for x in W: if x > L: break else: L -= x ans += 1 print(ans)