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

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

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

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

contains
subroutine die
    print*, -1
    stop
end subroutine

end program name