require 'set'
lines = readlines.map{|line| line.split(' ').map(&:to_i)}
set = Set.new
a=[]
c=0
d=0
for i in 1..lines[0][1]
	if lines[i]==[0,1] then
      puts "-1"
      d=1
      break
    end
    set=set.add?(lines[i][0])
    if set==nil then
      if !a.include?(lines[i][1]) then
        puts "-1"
        d=1
        break
      else
        next
      end
    end
    a.push(lines[i][1])
    c=c+lines[i][1]*(10**(lines[0][0]-lines[i][0]))
end
if d==0 then
	puts c
end