import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int L = sc.nextInt(); int N = sc.nextInt(); ArrayList wide = new ArrayList(); for( int i = 0 ; i < N ; i++ ){ wide.add(sc.nextInt()); } Collections.sort(wide); int w_sum = 0; int count = 0; for( int i = 0 ; i < N ; i++ ){ w_sum += wide.get(i); if( w_sum > L)break; count++; } System.out.println(count); } }