N,M=map(int,input().split())
keta=[-1]*N
a=[]
for i in range(M):
    c1,c2=map(int,input().split())
    a.append([c1,c2])


for p in a:
    k=p[0]
    s=p[1]
    if keta[k-1] == -1:
        keta[k-1] = s
    elif keta[k-1] != s:
        print(-1)
        exit()

    
for i in range(10**(N-1),10**N):
    Q= str(i)
    flag=1
    for j in range(N):
        if keta[j]!= -1 and Q[j]==str(keta[j]):
            flag *= 1
        elif keta[j]!= -1 and Q[j] != str(keta[j]):
            flag *= 0

    if flag==1:
        print(i)
        break
else:
    print(-1)
    