i,w['~~'];c(int*a,int*b){i=*a-*b;}main(j){for(;!~scanf("%d",w+i++)?qsort(w+2,w[1],4,c),~--*w?j+=!--w[j+1]:!printf("%d",j-1):1;);}