n,m=map(int,input().split())
L=[[] for i in range(n)]
for i in range(m):
    s,c=map(int,input().split())
    if (L[s-1] and L[s-1][0]!=c) or (s==1 and c==0):
        print(-1)
        break
    else:
        L[s-1].append(c)
else:
    for i in range(n) :
        if not(L[i]):
            if i==0:
                print(1,end='')
            else:
                print(0,end='') 
        else:
            print(L[i][0],end='')