n, _m = gets.chop.split.map(&:to_i)

sc = []
while line = gets
    sc << line.chomp.split(' ').map(&:to_i)
end

def judge(sc, n)
  falsy = '-1'
  arr = []

  sc.each do |el|
    if arr[el[0]] && arr[el[0]] <= el[1]
      next
    else
      arr[el[0]] = el[1]
    end
  end

  arr.shift

  if arr[0] == 0
    if arr.count == 1 && n == 1
      return puts 0
    else
      return puts falsy
    end
  end

  if arr[0].nil?
    return puts falsy
  end

  (0..(arr.count - 1)).each do |i|
    if arr[i].nil?
      arr[i] = 0
    end
  end

  ans = arr.join

  if ans.length != n
    return puts falsy
  end

  puts ans.to_i
end

judge(sc, n)
