n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
for i in range(10**(n-1),10**n):
    stri=str(i)
    c=0
    for j in range(m):
        if stri[sc[j][0]-1]==str(sc[j][1]):
            c+=1
    if c==m:
        print(i)
        break
    elif i==10**n-1:
        print(-1)
        break