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)) > 0 ) cycle
    ans = ans + c(i) * int( 10**( n - s(i) ) )
    o(s(i)) = o(s(i)) + 1
  end do
  
  if ( maxval( o ) > 1 ) ans = -1
  if ( o(n) == 0 .or. c(1) == 0 ) ans = -1
  
  print*, ans
  
  !call quicksort1( p, 1, int( n*(n-1) )+1 ) 

end program main

recursive subroutine quicksort1(a, first, last)
  implicit none
  integer(8),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  integer(8)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1
