n, m = map(int,input().split())
a = []
b = []
for i in range(m):
  x, y = map(int,input().split())
  a.append(x)
  b.append(y)
ans = 0

def conflict_check(a, b):
  ini = 0
  for i in range(m):
    for j in range(m-i-1):
      jj = i+1+j
      if a[i] == a[jj]:
        if b[i] != b[jj]:
          ini = -1
  return ini

if m != 0:
  ans += conflict_check(a, b)
  if ans != -1:
    if n != 1:
      if b[a.index(1)] == 0:
        ans -= 1
      else:
        for i in range(n):
          if (i+1 in a) == True:
            ans += b[a.index(i+1)]*10**(n-1-i)
    else:
      ans += b[a.index(1)]
else:
  if n != 1:
    ans = 10**(n-1)
    
print(ans)