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