class Heap
	require 'forwardable'
	extend Forwardable

	def initialize
		@array = []
		@index = {}
	end

	def add(obj, key)
		@array << [obj, key]
		@index[obj] = @array.size - 1
		lift_up(@array.size - 1)
	end

	def swap(i, j)
		u = @array[i]
		v = @array[j]
		@index[u[0]], @index[v[0]] = j, i
		@array[i], @array[j] = v, u
	end

	def lift_up(i)
		return if i == 0
		j = (i - 1) / 2
		if (@array[i][1] <=> @array[j][1]) < 0
			swap(i, j)
			lift_up(j)
		end
	end

	def del_min
		raise "heap is empty!" if empty?
		min = @array[0]
		if size > 1
			swap(0, @array.size-1)
			@array.pop
			lift_down(0)
		else
			@array.pop
		end
		@index.delete(min[0])
		min
	end

	def inc_key(obj, diff)
		i = @index[obj]
		@array[i][1] += diff
		lift_down(i)
	end

	def dec_key(obj, diff)
		i = @index[obj]
		@array[i][1] -= diff
		lift_up(i)
	end

	def del(obj)
		dec_key(obj, Float::INFINITY)
		del_min
	end

	def update_key(obj, new_key)
		i = @index[obj]
		return unless i
		return if (new_key <=> @array[i][1]) >= 0
		@array[i][1] = new_key
		lift_up(i)
	end

	def min_obj
		@array[0][0]
	end

	def min_key
		@array[0][1]
	end

	def lift_down(i)
		j = 2 * i + 1
		k = j + 1
		if k >= size
			return if j >= size
			if (@array[i][1] <=> @array[j][1]) > 0
				swap(i, j)
				lift_down(j)
			end
		else
			l = ((@array[j][1] <=> @array[k][1]) < 0 ? j : k)
			if (@array[i][1] <=> @array[l][1]) > 0
				swap(i, l)
				lift_down(l)
			end
		end
	end

	def_delegators :@array, :empty?, :size
end

loop do
	n, deadline = gets.split.map(&:to_i)
	break if n == 0
	customers = (1..n).map { gets.split.map(&:to_i) }		
	
	(1..n).each do |o|

		event_heap = Heap.new
		(0..customers.size-1).each do |i|
			event_heap.add([:start, i], 0)
		end

		queue_heap = Heap.new
		supported = {}
		finished = {}

		working = 0

		until event_heap.empty?
			t = event_heap.min_key
			break if t > deadline

			while !event_heap.empty? && event_heap.min_key == t
				(type, id), _ = event_heap.del_min
				support_time, wait_time, recall_time = customers[id]
				case type
				when :finish
					working -= 1
					finished[id] = 1
				when :start
					queue_heap.add(id, id)
					event_heap.add([:give_up, id], t + wait_time + 0.1)
				when :give_up
					if ! supported[id]
						queue_heap.del(id)
						event_heap.add([:start, id], t.to_i + recall_time)
					end
				end
			end

			until working == o || queue_heap.empty?
				id, _ = queue_heap.del_min
				support_time, wait_time, recall_time = customers[id]
				event_heap.add([:finish, id], t + support_time)
				supported[id] = 1
				working += 1
			end
		end
		if finished.size == n
			puts o
			break
		end
	end
end