Scanf.scanf "%d %d\n" (fun n m ->
  let r = ref [] in
  for i=0 to m-1 do
          let (p1,y1) = Scanf.scanf "%d %d\n" (fun p1 y1->
     (p1,y1)
    ) in
    r := (p1,y1):: !r
  done;
  r := List.rev !r;
  let r2 = List.sort (fun (_,x) (_,y) -> x-y) !r in
  let _,m2 = List.fold_left (fun (m,m2) (p,y) ->
          let n = try List.assoc p m with _ -> 0 in
          ((p,n+1)::m,((p,y),n+1)::m2)
  ) ([],[]) r2 in
  List.iter (fun (p,y) ->
    Printf.printf "%06d%06d\n" p (List.assoc (p,y) m2)
  ) !r
)
