题目1209:最小邮票数
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
new Task().solve() ;
}
}
class Task{
InputReader in = new InputReader(System.in) ;
PrintWriter out = new PrintWriter(System.out) ;
void solve(){
while(in.hasNext()){
int m = in.nextInt() ;
int n = in.nextInt() ;
int[] dp = new int[m+1] ;
Arrays.fill(dp , Integer.MAX_VALUE) ;
dp[0] = 0 ;
while(n-- > 0){
int v = in.nextInt() ;
if(v > m) continue ;
for(int i = Math.max(0 , m - v) ; i >= 0 ; i--){
if(dp[i] != Integer.MAX_VALUE){
dp[i+v] = Math.min(dp[i+v] , dp[i] + 1) ;
}
}
}
out.println(dp[m] == Integer.MAX_VALUE ? 0 : dp[m]) ;
//out.flush();
}
out.flush();
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = new StringTokenizer("");
}
private void eat(String s) {
tokenizer = new StringTokenizer(s);
}
public String nextLine() {
try {
return reader.readLine();
} catch (Exception e) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
}