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; for( int i = 0 ; i < N ; i++){ w_sum += wide.get(i); if( w_sum > L){ w_sum -= wide.get(i); } } System.out.println(w_sum); } }