def upper_bound(arr, v)
  l = -1
  r = arr.size
  while l + 1 < r
    m = (l + r) / 2
    if arr[m][0] < v then l = m
    else r = m
    end
  end
  r
end

loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0
  pcs = n.times.map{ [] }
  m.times do
    t, s, d = gets.split.map(&:to_i)
    pcs[s - 1] <<  [t, d - 1]
  end
  pcs.map!{ |pc| pc.sort }
  time = 0
  infected_pc = 0
  loop do
    idx = upper_bound(pcs[infected_pc], time)
    if idx == pcs[infected_pc].size
      puts infected_pc + 1
      break
    end
    infected_pc, time = pcs[infected_pc][idx]
  end
end