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) )
  
  ans = 0 
  o   = 0
  do i = 1, m
    if( o(s(i)) == 1 ) cycle
    ans = ans + c(i) * int( 10**( n - s(i) ) )
    o(s(i)) = o(s(i)) + 1
  end do
  
  if ( o(n) == 0 ) ans = -1
  
  print*, ans
  
end program main
