# -*- coding: utf-8 -*-
n, m = map(int,input().split())
a = 0
b = 0
c = 0
a1 = 0
b1 = 0
c1 = 0

for i in range(m):
    x, y = map(int, input().split())
    if x == 1 and y == 0:
      print("-1")
      exit()
    elif x == 1:
      if a1 !=0 and a != y:
        print("-1")
        exit()
      a = y
      a1 = 1 
    elif x == 2:
      if (b1 !=0 and b != y):
        print("-1")
        exit()
      b = y
      b1 = 1 
    elif x == 3:
      if (c1 !=0 and c != y ):
        print("-1")
        exit()
      c = y
      c1 = 1 
if n == 1:
  A = a
elif n == 2:
  A = a*10+b  
elif n == 3:
  A = a*100+b*10+c
  
print(A)
