n,m=map(int,input().split())
S={}
for i in range(m):
    s,c=map(int,input().split())
    if s not in S:
        S[s]=c
    elif S[s]!=c:
        print(-1)
        exit()
    if n!=1 and s==1 and c==0:
        print(-1)
        exit()
    if n<s:
        print(-1)
        exit()

for i in range(1,1000):
    if len(str(i))==n:
        flag=True
        for j in S.keys():
            if int(str(i)[j-1])!=S[j]:
                flag=False
        if flag:
            print(i)
            exit()
print(-1)