n,m=list(map(int,input().split()))
a=[-1]*n
flg=0
for i in range(m):
    s,c=list(map(int,input().split()))
    if a[s-1]!=-1 and a[s-1]!=c:
        flg=1
    a[s-1]=c

if (flg==1):
    print("-1")
    exit()

if a[n-1]==-1:
    print("-1")
    exit()

for i in range(n):
    if a[i]==-1:
        a[i]=0

print("".join(map(str,a)))
