import java.util.*; import java.lang.*; import java.io.*; class Main{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); int wid = Integer.parseInt(sc.next()); int num = Integer.parseInt(sc.next()); List box = new ArrayList(); for(int i = 0; i < num; i++){ box.add(Integer.parseInt(sc.next())); } Collections.sort(box); int temp = 0; int ct = 0; for(Iterator it = box.iterator(); it.hasNext();){ temp += ((Integer)it.next()).intValue(); if(temp <= wid) { ct++; } else {break;} } System.out.println(ct); } }