https://www.acmicpc.net/problem/1590
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int t=s.nextInt();
int count=-1;
int min=10000000;
int sum=0;
for(int i=0;i<n;i++){
int si=s.nextInt();
int li=s.nextInt();
int ci=s.nextInt();
sum=si;
for(int j=0;j<ci;j++){
if(t<=sum){
count=sum-t;
break;
}
sum+=li;
}
if(count<=min && count!=-1) min=count;
}
if(count==-1) System.out.print(count);
else System.out.print(min);
}
}