program main

  implicit none

  integer    :: n, m
  integer,allocatable :: s(:), c(:)

  integer,allocatable :: o(:,:)
  integer    :: i, j, k, ans

  read(*,*) n, m
  allocate( s(m) )
  allocate( c(m) )
  do i = 1, m
    read(*,*) s(i), c(i)
  end do
  allocate( o(n,2) )
  
  ans = 0 
  o   = 0
  do i = 1, m
    if( o(s(i),1) == 1 .and. o(s(i),2) <= c(i) ) cycle
    o(s(i),1) = o(s(i),1) + 1
    o(s(i),2) = c(i)
  end do
  
  do i = 1, 3
    ans = ans + o(i,2) * int( 10**( n - i ) )
  end do

  if ( o(1,2) == 0 ) ans = -1
  
  print*, ans
  
end program main
