program kadai
integer  ::  N,M,i
integer  ::  a(3)
integer  ::  ans
integer,allocatable  ::  s(:),c(:)


read(*,*) N,M
allocate(s(M))
allocate(c(M))
do i=1,M
    read(*,*) s(i),c(i)
end do

a=10
do i=1,M
    if (a(s(i))==10) then
        a(s(i))=c(i)
    else if (a(s(i))/=c(i)) then
        write(*,*) -1
        stop
    end if
end do

if (a(4-N)==0) then
    write(*,*) -1
    stop
end if

do i=1,3
if (a(i)==10) then
    a(i)=0
end if
end do

ans=100*a(1) + 10*a(2) + a(3)
write(*,*) ans


stop



end program kadai
