N,M=map(int,input().split())
rest=[[] for _ in range(N)]
r2=[]
end=0
flag=0
buf=""
ans=float("inf")
end=0
for i in range(M):
    s,c=map(int,input().split())
    if len(rest[s-1])==0:
        rest[s-1].append(c)
    elif rest[s-1].count(c)==0:
        end=1
        break
#print(rest)

if N == 1:
    l=range(0,10**N,1)
else:
    l=range(10**(N-1),10**N,1)

if end!=1:
    for i in l:
        buf=str(i)
        #print(i)
        for j in range(N):
            if len(rest[j])==1:
                if buf[j]!=str(rest[j][0]):
                    fail=1
                    break
        if fail==0:
            ans=i
            flag=1
            break
        fail=0
if (flag==1):
    print(ans)
else:
    print("-1")