n,m = map(int,input().split())
p = [[int(i) for i in input().split()] for _ in range(m)]

a=-1
b=-1
c=-1
for i,j in p:
    if i==1 and j == 0:
        print(-1)
        exit()
    if i==1:
        if a==-1:
            a=j
        elif a!=-1 and a!=j:
            print(-1)
            exit()
    if i==2:
        if b==-1:
            b=j
        elif b!=-1 and b!=j:
            print(-1)
            exit()
    if i==3:
      	if c==-1:
            c=j
      	elif c!=-1 and c!=j:
            print(-1)
            exit()
if n==1:
    if c<0:
      print(0)
elif n ==2:
    if b<0:
      b==1
    if c<0:
      c=0
    print('%d%d' % (b,c))
else:
    if a<0:
      a=1
    if b<0:
      b=0
    if c<0:
      c=0
    print('%d%d%d' % (a,b,c))

