https://www.acmicpc.net/problem/1590
n,t=map(int,input().split())
count=-1
min=10000000
sum=0
for i in range(n):
si,li,ci=map(int,input().split())
sum=si
for j in range(ci):
if t<=sum:
count=sum-t
break
sum+=li
if count<=min and count!=-1: min=count
if count==-1: print(count)
else: print(min)