l = int(input()) n = int(input()) w = list(map(int, input().split())) w_list = sorted(w) w_len = len(w_list) count = 0 souwa = 0 for i in range(w_len): souwa += w_list[i] if l >= souwa: count += 1 print(count)