n,m=map(int,input().split())
s=[]
c=[]
ans=1000
if m == 0:
    if n == 1:
        ans=0
    elif n==2:
        ans=10
    elif n==3:
        ans=100
else:
    for i in range(m):
        s.append(0)
        c.append(0)

    for i in range(m):
        s[i],c[i]=map(int,input().split())
    
    for i in range(0,1000):
        tmp=True
        for j in range(m):
            if len(str(i)) < s[j]:
                tmp= False
                break
            elif int(str(i)[s[j]-1]) != c[j]:
                tmp = False
                break
        if tmp == True:
            ans=i
            break
    if ans == 1000:
        ans = -1
    if ans == 0:
        if n == 2:
            ans = 10
        if n == 3:
            ans = 100

print(ans)