# -*- coding:utf-8 -*- 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) / t end = (x+loss+w) / t if start % 2 == 1: loss += t * (start + 1) - (x+loss) elif end % 2 == 1: loss += t * (end + 1) - (x+loss) print ans + loss