program sample
    implicit none
  
    integer(8) :: i,j,m,n,a,b,ans
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n,m
    allocate(x(n))
    x(:)=-1
    do i=1,m
        read(*,*)a,b
        if(a==1 .and. b==0)then
            write(*,*)'-1'
            stop
        else if(x(a)==-1)then
            x(a)=b
        else if(x(a)/=b)then
            write(*,*)'-1'
            stop
        end if
    end do
    ans=0
    do i=1,n
        if(x(i)==-1)then
            x(i)=0
        end if
        ans=ans+x(i)*10**(n-i)
    end do
    write(*,*)ans
  
    stop
end program sample
  

