n,m=map(int,input().split())
a=[0]*3

for i in range(m):
    s,c=map(int,input().split())
    a[s-1]=c

if a[0]==0:
    print(-1)
else:
    b=""
    for i in range(3):
        b+=str(a[i])
    print(b)