n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
if n==1:
    c0=sc[0][0]
    for i in range(m):
        s=sc[i][0]
        c=sc[i][1]
        if c!=c0:
            print(-1)
            exit()
    print(c0)
else:
    ans=10**5
    for i in range(10**(n-1),10**n):
        I=str(i)
        flag=True
        for j in range(m):
            s,c=sc[j][0],sc[j][1]
            if s==1 and c==0:
                print(-1)
                exit()
            if I[s-1]!=str(c):
                flag=False
                continue
        if flag:
            ans=min(ans,i)
    if ans==10**5:
        print(-1)
    else:
        print(ans)