import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class Main{ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int L = Integer.parseInt(br.readLine()); int N = Integer.parseInt(br.readLine()); String s[] = br.readLine().split(" "); ArrayList<Integer> w = new ArrayList<Integer>(); for(int i=0;i<N;i++){ w.add(Integer.parseInt(s[i])); } Collections.sort(w); int sum=0,result = 0; for(;result < N;result++){ sum+=w.get(result); if(sum > L){break;} } System.out.println(result); } }