N,M=map(int,input().split())
l=[]
for i in range(N):
    l.append([i,10])
for _ in range(M):
    a,b=map(int,input().split())
    if a==1:
        if b<l[a-1][1] and b!=0:
            l[a-1][1] = b
    else:
        if b<l[a-1][1]:
            l[a-1][1]=b

if M>1 and l[0][1]==10:
    print(-1)
elif M==0:
    if N==1:print(0)
    else: print(10**(N-1))
else:
    for i in range(N):
        if l[i][1]==10:
            l[i][1]=0
        print(str(l[i][1]),end="")

