program main
  integer :: N,M
  integer,allocatable :: s(:),c(:)
  integer :: max_, min_, tmp
  integer :: i,j
  logical :: check
  read(*,*) N,M
  if (M == 0) then
     write(*,'(i0)') 10**(N-1)
     stop
  end if
  allocate(s(M),c(M))
  do i = 1,M
     read(*,*) s(i), c(i)
  end do
  !
  do i = 1,M
     if (S(i) == 1 .and. c(i) == 0) then
        write(*,'(i0)') -1
        stop
     end if
  end do
  !
  do i = 1,M
     do j = i,M
        if ( S(j) == S(i) ) then
           if (c(j) /= c(i) ) then
              write(*,'(i0)') -1
              stop
           end if
        end if
     end do
  end do
  !
  !
  !
  max_ = 10**N - 1
  min_ = 10**(N-1)
  tmp = max_
  do j = min_, max_
     check = .false.
     do i = 1,M
        if ( digit(s(i),j,N)  == c(i) ) then
           check = .true.
        else
           check = .false.
           exit
        end if
     end do
     if (check .and. tmp > j) then
        tmp = j
     end if
  end do
  write(*,'(i0)') tmp
contains
  integer function digit(s,i,n)
    integer :: s,i,n
    character(len=N) :: tmp

    write(tmp,'(i0)') i
    read(tmp(s:s),*) digit
    return
  end function digit
end program main
