import java.util.Scanner;
class ZXWT {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int v = sc.nextInt();
int total = sc.nextInt();
int[] things = new int[30];
int[] dp = new int[20000];
for(int i=0;i<total;i++){
things[i] = sc.nextInt();
}
for(int i=0;i<total;i++){
for(int j=v;j>=things[i];j--){
dp[j] = getMax(dp[j],dp[j-things[i]]+things[i]);
}
}
System.out.print(v-dp[v]);
}
public static int getMax(int a, int b){
return a>b?a:b;
}
}