n, m = map(int, input().split())

sc = []
flag = 1

for i in range(m):
  if flag != 1:
    break
  s, c = map(int, input().split())
  for x in sc:
    if s == x[0] and c != x[1]:
      print(-1)
      flag = 0
      break
  sc.append((s,c))
  
if flag == 1 and (1, 0) in sc:
  print(-1)
  flag = 0
            
sc = list(set(sc))
ans = 0

for x in sc:
  ans += x[1] * 10 ** (n - x[0])
  
if flag == 1 and ans < 10 ** (n-1):
  print(ans + 10 ** (n-1))
elif flag == 1:
  print(ans)