n,m=map(int,input().split())
sc=[[0,0] for i in range(m)]
for i in range(m):
    sc[i] = list(map(int,input().split()))
f=0
dic = dict()
for sc0 in sc:
    if sc0[0] in dic.keys():
        if sc0[1]!=dic[sc0[0]]:
            f=1
    dic[sc0[0]]=sc0[1]
if f ==1 or [1,0] in sc:
    print(-1)
else:
    ans = ["0"]*n
    for i in dic.keys():
        ans[i-1] = str(dic[i])
        
    if ans[0]=="0":
        ans[0]="1"
    
    print( "".join(ans) )