L = input() N = input() e = map(int, raw_input().split()) e.sort j =0 sum = 0 while sum<=L : sum = sum + e[j] j = j + 1 else: print j