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]
      return puts falsy
    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)

# N, M = gets.chomp.split.map(&:to_i)

# arr = Array.new(N)
 
# M.times {
#   s, c = gets.chomp.split.map(&:to_i)
#   if arr[s - 1] && arr[s - 1] != c
#     puts "-1"
#     exit
#   end
#   arr[s - 1] = c
# }
  
# if arr.count > 1 && arr[0] == 0
#     puts "-1"
#     exit
# end
  
# if !arr[0] && arr.count > 1
#   arr[0] = 1
# end
 
# ret = arr.reduce(""){|sum, i|
#   if (i) then
#     sum = sum << i.to_s
#   else
#     sum = sum << "0"
#   end
# }
 
# puts ret