n,m=map(int,input().split())
l=[-1]*n
check=False
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        break
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        break
    if i==m-1:
        check=True
if n!=1 and l[1]==-1:
    l[1]=1
if check:
    for num in l:
        if num==-1:
            print(0,end='')
        else:
            print(num,end='')
    print()
else:
    print(-1)
