def foo
  n, m = gets.split.map(&:to_i)
  o = [nil]*n
  m.times do
    s, c = gets.split.map(&:to_i)
    return -1 if o[s-1] && o[s-1] != c
    o[s-1] = c
  end

  return -1 if o[0] == 0
  o[0] ||= 1
  1.upto(n-1){|i| o[i] ||= 0}

  return o.join.to_i
end

p foo()
