n,m=map(int,input().split())
a=[0,0,0]
ans=True
for _ in range(m):
    s,c=map(int,input().split())
    if a[3-n+s-1]==0:
        a[3-n+s-1]=c
    elif a[3-n+s-1]!=c and a[3-n+s-1]!=0:
        ans=False
    if s==1 and c==0 and n!=1:
        ans=False

b=''
if ans:
    for i in range(len(a)):
        b+=str(a[i])
    print(int(b))
else:
    print(-1)