l,w[9999],i;main(j){for(scanf("%d%*d",&l);~scanf("%d",w+i++);)for(j=i;--j;)w[j-1]>w[j]?w[j-1]^=w[j]^=w[j-1]^=w[j]:0;for(i=*w;w[j]&&i<=l;i+=w[++j]);i=!printf("%d",j);}