import java.util.*;
import java.util.stream.IntStream;

public class Pehrs {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int w = input.nextInt();
        int[] cost = new int[n+1];
        cost[0] = w;
        for (int i = 1; i < n+1; i++) {
            int parent = input.nextInt();
            int capacity = input.nextInt();
            int fill = input.nextInt();
            cost[i] = capacity-fill + Math.max(cost[parent]-capacity, 0);
        }
        System.out.println(IntStream.of(cost).min().getAsInt());
    }
}
