program main
    implicit none
    integer n, m
    integer, allocatable, dimension(:) :: s, c
    integer i,j,k,l, flag
    integer, dimension(3) :: x
    read(*,*) n, m
    allocate(s(m))
    allocate(c(m))

    do i = 1, m
        read(*,*) s(i), c(i)
    end do

    x = 0
    flag = 0

    do i = 1,m
        if(x(s(i)) /= 0) then
            if(x(s(i)) /= c(i)) then
                flag = -1
                exit
            end if
        else
            x(s(i)) = c(i)
        end if

!--------------
        if(n == 3) then
            if(s(i) == 1) then
                if(c(i) == 0) then
                    flag = -1
                end if
            end if
        end if

!---------------
        if(n == 2) then
            if(s(i) == 1) then
                if(c(i) == 0) then
                    flag = -1
                end if
            end if
        end if

    end do

    
    if (flag == -1) then
        write(*,*) -1
    else
        if (n == 3) then
            if (x(1) == 0) then
                x(3) = 1
            end if
        end if

        if (n == 2) then
            if (x(2) == 0) then
                x(2) = 1
            end if
        end if

        write(*,*) 100*x(1)+10*x(2)+x(3)
    end if

end program