n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(list(map(int,input().split())))
a=sorted(a,key=lambda x:x[0])
if n>=2 and a[0]==[1,0]:
    print(-1)
    exit()
for i in range(m-1):
    if a[i][0]==a[i+1][0] and a[i][1]!=a[i+1][1]:
        print(-1)
        exit()
    elif a[i]==a[i+1]:
        a.pop(i)
        if i+2==len(a):
            break
j=0
b=''
f=0
print(a)
for i in range(n):
    if a[j][0]-1!=i:
        b+='0'
        j+=1
    else:
        b+=str(a[j][1])
print(b)