n,m=map(int,input().split())
sitei=[]
for i in range(m):
    a,b=map(int,input().split())
    sitei.append([a-1,b])

ans=[-1]*n

kano=True
for i in range(m):
    if(ans[sitei[i][0]]==-1):
        ans[sitei[i][0]]=sitei[i][1]
    elif(ans[sitei[i][0]]!=sitei[i][1]):
        kano=False

if(ans[0]==0):
    kano=False
if(ans[0]==-1):
    ans[0]==1

if(not kano):
    print(-1)
else:
    kotae=""
    for i in range(m):
        if(ans[i]==-1):
            kotae+="0"
        else:
            kotae+=str(ans[i])
    print(kotae)