      PROGRAM guessTheNumber
      IMPLICIT NONE
      integer :: n,num(3),m
      integer,allocatable :: s(:),c(:)
      integer :: i,ii,k
      
      read*,n,m
      allocate( s(m),c(m) )
      do i = 1,m
        read*,s(i),c(i)
      end do
 !     print*,n,m
 !     do i = 1,m
 !       print*,s(i),c(i)
 !     end do
      
      outer:do i = 0,999
        if( n==1 .and. .not.(0  <=i .and. i<=9  ) ) cycle
        if( n==2 .and. .not.(10 <=i .and. i<=99 ) ) cycle
        if( n==3 .and. .not.(100<=i .and. i<=999) ) cycle
      !  if( n==1 .and. i==10  ) exit
     !   if( n==2 .and. i==100 ) exit
        ii = i
        do k = 1,3
          num(k) = ii - ii/10*10
          ii = ii / 10
        end do
        
      !  if( n==2 .and. num(2)==0 ) cycle
      !  if( n==3 .and. num(3)==0 ) cycle
 ! print*,num
      
      do k = 1,m
        if( num(3-s(k)+1)/=c(k) ) cycle outer
      end do
      print*,i;stop
      
      end do outer
      
      print*,'-1'
      
      
      END PROGRAM