L = int(input()) N = int(input()) Wn = list(map(int,input().split())) Wn_arr = sorted(Wn) width = 0 count = 0 while count <= N-1: width += Wn_arr[count] count += 1 if width > L: width -= Wn_arr[count - 1] count -= 1 break print(count)