Jobs
문제
You have a successful business where you make money by completing jobs for your clients. Currently, you can choose from N one-time jobs, numbered from to .
Completing job will make you a profit of euros. The profit may also be negative ().
Some jobs depend on another job. That is, there may be a job numbered that must be completed before the -th job can be started. Hence, a job with a large profit may be less attractive than it seems if it depends on a job with a negative profit. If , the -th job has no dependency.
You currently have euros and can decide which jobs to do and in which order to do them, as long as the dependencies are respected. Moreover, the amount of money you own may not become negative at any point.
Calculate the maximum profit you can make by choosing to complete some (possibly none) of the jobs in a selected order.
입력
The first line contains two integers and s – the number of jobs and the amount of money you initially own respectively.
Then, lines follow. The -th of them contains two integers and – the profit and the number of the prerequisite job for the -th job, respectively. If , the -th job does not have a job dependency.
출력
Your program should output a single integer – the maximum profit that you can make.
예제
예제 1
6 1 3 0 -3 1 -5 0 2 1 6 3 -4 5
6