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


read(*,*) N,M
allocate(s(M))
allocate(c(M))
allocate(a(N))
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 (N>1 .and. a(1)==0) then
    write(*,*) -1
    stop
end if

if (a(1)==10) then
    a(1)=1
end if
if (N>1) then
    do i=2,N
        if (a(i)==10) then
            a(i)=0
        end if
    end do
end if

ans=0
!#write(*,*) a
do i=1,N
    ans=ans+a(i)*(10**(N-i))
end do
write(*,*) ans


stop



end program kadai
