def sum(arr):
  ans = 0
  for i in range(len(arr)):
    ans = ans * 10 + arr[i]
  return ans
a = input()

n,m = a.split()
n = int(n)
m = int(m)
arr = []
for i in range(n+1):
  arr.append(0)
p = 0
for i in range(m):
  a = input()
  left,num = a.split()
  left = int(left)
  num = int(num)
  if arr[left] != 0:
    if arr[left] != num:
      p = 1
      print(-1)
      break
  else:
    arr[left] = num
if arr[1] == 0 and n != 1:
  arr[1] = 1
arr[0] = 0
if p == 0:
  print(sum(arr))
