program name
    implicit none
    integer(4):: n,m
    integer(4):: s,c
    integer(4),allocatable:: keta(:)
    integer(4):: i,ans

    read*, n,m
    allocate(keta(n))
    
    keta(:) = -1
    do i=1,m
        read*, s,c
        
        if (keta(s) /= -1 .and. keta(s) /= c) call die
        keta(s) = c
    end do

    if (keta(1) == 0 .and. n > 1) call die
    if (keta(1) == -1 .and. n > 1) keta(1) = 1

    do i=1,n
        if (keta(i) == -1) keta(i) = 0
    end do

    ans=0
    do i=1,n
        ans=ans+keta(i)*10**(n-i)
    end do

    print*, ans

contains
subroutine die
    print*, -1
    stop
end subroutine

end program name