program main
  implicit none
  integer :: i, n, m, s, c, ans = 0
  integer, allocatable :: x(:)

  read *, n, m
  allocate (x(n))
  x(:) = -1

  do i = 1, m
    read *, s, c
    if (x(s) /= -1 .and. x(s) /= c) ans = -1
    if (s == 1 .and. n /= 1 .and. c == 0) ans = -1
    x(s) = c
  end do
  do i = 1, n
    x(i) = max(0, x(i))
  end do
  if (ans == -1) then
    print '(i0)', -1
  else
    if (n == 1) then
      print '(i0)', x(1)
    else
      ans = ans + max(1, x(1)) * (10 ** (n-1))
    do i = 2, n
      ans = ans + x(i) * (10 ** (n-i))
    end do
    end if
    print '(i0)', ans
  end if
end program