#!usr/bin/env python if __name__ == '__main__': L = input() N = input() W = map(int, raw_input().split()) print W W = sorted(W) print W sum = 0 for i in range(N): sum = sum + W[i] if sum > L: print i exit(0) print N exit(0)