# -*- coding:utf-8 -*- import math if __name__ == "__main__": n,l = map(int,raw_input().split()) cross =[] for i in xrange(n): xi,wi,ti = map(int,raw_input().split()) cross.append((xi,wi,ti)) ans = l loss = 0 for x,w,t in cross: start = (x+loss) / float(t) end = (x+loss+w) / float(t) if math.floor(start) % 2 == 1: if math.ceil(start) == start: start += 1 loss += t * math.ceil(start) - (x+loss) elif math.floor(end) % 2 == 1: if math.ceil(end) == end: end += 1 loss += t * math.ceil(end) - (x+loss) print int(ans + loss)