n, m = map(int, input().split())
array = [None] * n
for i in range(m):
  keta, num = map(int, input().split())
  if n >= 2 and keta == 1 and num == 0:
    print(-1)
    break
  if array[keta-1] != None and array[keta-1] != num:
    print(-1)
    break
  array[keta-1] = num
  
  if i == m-1:
    ans = 0
    for k in range(n):
      if array[k] != None:
        ans += 10**(n-1-k)*array[k]
    print(ans)
  