class Heap
	require 'forwardable'
	extend Forwardable

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

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

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

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

	def del_min
		min = @array[0]
		if size > 1
			swap(0, @array.size-1)
			@array.pop
			lift_down(0)
		else
			@array.pop
		end
		@index.delete(min)
		min
	end

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

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

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

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

def check(ope_num, customers, deadline)
	queue_heap = Heap.new
	supported = {}
	finished = {}
	working = 0

	start_events = (0..deadline).map { [] }
	giveup_events = (0..deadline).map { [] }
	finish_events = (0..deadline).map { [] }
	start_events[0] = (0..customers.size-1).to_a

	(0..deadline).each do |t|
		abort_flag = false

		start_events[t].each do |id|
			support_time, wait_time, recall_time = customers[id]
			queue_heap.add(id)
			gt = t + wait_time
			giveup_events[gt] << id if gt <= deadline
		end

		finish_events[t].each do |id|
			finished[id] = 1
			working -= 1
		end

		until working == ope_num || queue_heap.empty?
			id, _ = queue_heap.del_min
			support_time, wait_time, recall_time = customers[id]
			ft = t + support_time
			if ft <= deadline
				finish_events[ft] << id 
				supported[id] = 1
				working += 1
			else
				abort_flag = true
				break
			end
		end
		break if abort_flag

		giveup_events[t].each do |id|
			next if supported[id]
			support_time, wait_time, recall_time = customers[id]
			queue_heap.del(id)
			st = t + recall_time
			if st + support_time <= deadline
				start_events[st] << id
			else
				abort_flag = true
				break
			end
		end
		break if abort_flag
	end

	return finished.size == customers.size
end

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

	lower_bound = (customers.map(&:first).inject(:+) / deadline.to_f).ceil
	(lower_bound..n).each do |o|	
		if check(o, customers, deadline)
			puts o
			break
		end
	end
end