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]==[1,0] && lines[0][0]>1 then
      puts -1
      d=1
      break
    end
    b=set.add?(lines[i][0])
    if b==nil then
      if !a.include?([lines[i][1],lines[i][0]]) then
        puts -1
        d=1
        break
      else
        next
      end
    end
    a.push([lines[i][1],lines[i][0]])
    c=c+lines[i][1]*(10**(lines[0][0]-lines[i][0]))
end
if d==0 && c<10**(lines[0][0]-1) then
  c=c+10**(lines[0][0]-1)
end
if d==0 then
	puts c
end