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=0;i<=l&&w[j+!~j];i+=w[++j]);i=!printf("%d",j);}