import sys
n,m=map(int,input().split())
l=[0]*n
k=-1
for i in range(n):
    s,c=map(int,input().split())
    if s==1:
        if c==0:
            print(-1)
            sys.exit()
    if l[s-1]!=0:
        if l[s-1]==c:
            pass
        else:
            print(-1)
            sys.exit()
    l[s-1]=c
a=""
for j in range(n):
    a+=str(l[j])
if a[0]=="0":
    a[0]=="1"
print(int(a))