import heapq def solve(): n,y,z = map(int, input().split()) avail = [] # (x, c) toohigh = [] # (l, x, c) for _ in range(n): c,l,x = map(int, input().split()) if l <= y: avail.append((-x, c)) else: toohigh.append((l, x, c)) heapq.heapify(avail) heapq.heapify(toohigh) count = 0 while z > y and avail: count += 1 x,c = heapq.heappop(avail) x = -x y += x c -= 1 if c > 0: heapq.heappush(avail, (-x, c)) while toohigh and toohigh[0][0] <= y: l,x,c = heapq.heappop(toohigh) heapq.heappush(avail, (-x, c)) if y >= z: print(count) else: print(-1) if __name__ == "__main__": solve()