#include #include int com_asc_int(const void *n1,const void *n2){ if(*(int*)n1 > *(int*)n2)return 1; else if(*(int*)n1 < *(int*)n2)return -1; else return 0; } int main(){ int n,coin;scanf("%d %d",&n,&coin); if(coin > n){ printf("%d",-1); return 0; } int a[100000],b[100000];for(int i = 0;i < n-1;i++)scanf("%d %d",&a[i],&b[i]); int ans; int count[100000]; //qsort(a,n,sizeof(int),com_asc_int); for(int i = 0;i < n;i++){ for(int j = i;j < n;j++){ if(i+1 == a[j])count[i]++; } } for(int i = 0;i < n;i++) printf("count[%d] = %d\n",i+1,count[i]); coin--; for(int i = 0;i < n;i++){ if(coin <= 0)break; if(coin >= count[i]){ ans += count[i]; coin -= count[i]; }else ans += coin; } printf("%d",ans); }