infix &&
fun op && (reader1, reader2) input =
    case reader1 input of
        NONE => NONE
      | SOME (result1, rest) =>
        (case reader2 rest of
             NONE => NONE
           | SOME (result2, rest) => SOME ((result1, result2), rest))

type constraint = (int * int option) list
exception Invalid
(* 1-origin *)
fun makeNConstraint n = List.tabulate (n, fn i => (i + 1, NONE))
fun notStartZero [(1, SOME 0)] = true
  | notStartZero ((1, SOME 0) :: _) = false
  | notStartZero ((1, SOME _) :: _) = true
  | notStartZero ((1, NONE) :: _) = true
  | notStartZero _ = raise Fail "bug: not start index with 1"
fun validConstraint constraint =
    if notStartZero constraint then () else raise Invalid
fun updateC (index, num) (orig as (i, NONE)) =
    if i = index then (i, SOME num) else orig
  | updateC (index, num) (orig as (i, SOME n)) =
    if i = index andalso not (n = num) then raise Invalid
    else orig
fun updateConstraint constraint c = map (updateC c) constraint
fun setConstraint lineReader instream constraint =
    case lineReader instream of
        NONE => constraint
      | SOME (c as (index, num), instream) =>
        let
          val constraint = updateConstraint constraint c
        in
          setConstraint lineReader instream constraint
        end
fun makeSmallestNumber nil = nil
  | makeSmallestNumber [(1, _)] = [(1, 0)]
  | makeSmallestNumber ((1, NONE) :: cs) = (1, 1) :: makeSmallestNumber cs
  | makeSmallestNumber ((index, NONE) :: cs) =
    (index, 0) :: makeSmallestNumber cs
  | makeSmallestNumber ((index, SOME num) :: cs) =
    (index, num) :: makeSmallestNumber cs
fun printNumber nil = ()
  | printNumber ((_, num) :: rest) = (print (Int.toString num );
                                      printNumber rest)

fun main () =
    let
      val io = TextIO.stdIn
      val instream = TextIO.getInstream io
      val getc = TextIO.StreamIO.input1
      val intReader = Int.scan StringCvt.DEC getc
      val lineReader = intReader && intReader
      val ((n, m), instream) = valOf (lineReader instream)
                               handle Option.Option
                                      => raise Fail "bug: invalid input"
      val constraint = makeNConstraint n
      val constraint = setConstraint lineReader instream constraint
      val () = TextIO.setInstream (io, instream)
      val () = validConstraint constraint
      val numbers = makeSmallestNumber constraint
    in
      printNumber numbers
    end handle Invalid => print "-1"
val () = main ()
