#include #include #define MIN(a,b) ((a)<(b)?(a):(b)) void run(void){ int c,n; scanf("%d%d",&c,&n); const int inf=1000000; int *dp=(int *)calloc(c+1,sizeof(int)); for(int i=1;i<=c;i++) dp[i]=inf; while(n--){ int a; scanf("%d",&a); for(int i=a;i<=c;i++) dp[i]=MIN(dp[i],dp[i-a]+1); } printf("%d\n",dp[c]!=inf?dp[c]:-1); } int main(void){ run(); return 0; }