   program abc157c
      implicit none
      integer::N,M,i,j,x,y
      integer,allocatable,dimension(:)::A
      integer,allocatable,dimension(:)::S,C

      read *,N,M
      allocate(A(N))
      A=10
      allocate(S(M),C(M))

      do i=1,M
         read *,S(i),C(i)
         if (S(i)==1.and.C(i)==0) then
            print *,'-1'
            go to 10
         end if
      end do

      do i=1,M
         x=S(i)
         y=C(i)
         do j=i+1,M
            if (x==S(j).and.y/=C(j)) then
               print *,'-1'
               go to 10
            end if
         end do
      end do

      do i=1,N
         do j=1,M
            if (A(S(j))>C(j)) A(S(j))=C(j)
         end do
         if (A(i)==10) A(i)=0
         write(*,'(I1)',advance='no') A(i)
      end do

10    continue
      stop

   end program abc157c