n = list(map(int,input().split()))
a=[0,0,0]
r =0
for i in range(n[1]):
    s,c=map(int,input().split())
    if a[s-1]==0:
        a[s-1]=c
    elif a[s-1]!=c:
        r=1
if r==0:
    if n[0]==3:
        if a[0]==0:
            print('-1')
        else:
            for a_ in a:
                print(a_, end='')
    elif n[0]==2:
        if a[0]!=0 or a[1]==0:
            print('-1')
        else:
            for a_ in a:
                print(a_, end='')
    else:
        for a_ in a:
            print(a_, end='')
else:
    print('-1')