#!/usr/bin/env python3
n, w = map(int, input().split())
cost = {0: w}
for i in range(1, n+1):
    p, c, f = map(int, input().split())
    cost[i] = c-f + max(cost[p]-c, 0)
print(min(cost.values()))