# coding: utf-8
class Case05

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  # 読込
  def read
    @n, @m = gets.chomp.split.map(&:to_i)
    @a = []
    @b = []
    @c = []
    @m.times do
      t = gets.chomp.split.map(&:to_i)
      @a << t[0]
      @b << t[1]
      @c << gets.chomp.split.map(&:to_i)
    end
    @t = []
    1.upto(@m) do |i|
      @t << [ @a[i-1], @c[i-1] ]
    end
  end

  # 回答
  def solve
    @t.sort! {|x,y| x[0] <=> y[0] }                                   
  end
  
  # 出力
  def output
  end

end

Case05.new.execute if $0 == __FILE__

