import numpy as np
N,M = map(int,input().split())
N=int(N)
M=int(M)
s = []
c = []
bo=False
n1=0
n2=0
n3=0
for i in range(0,M):
    si,ci=map(int,input().split())
    s.append(si)
    c.append(ci)
for i in range(0,M):
    for j in range(0,M):
        if s[i]==s[j] and c[i]!=c[j]:
            bo=True
        elif N==2 and s[i]==2 and c[i]==0 :
            bo==True
        elif N==3 and s[i]==1 and c[i]==0 :
            bo==True
for i in range(0,M):
    if s[i]==1:
        n1=c[i]
    elif s[i]==2:
        n2=c[i]
    elif s[i]==3:
        n3=c[i]
if bo==True:
    print("-1")
else:
    if N==1 and (n1!=0 or n2!=0):
        print("-1")
    elif N==2 and n1!=0:
        print("-1")
    elif N==3 and n1==0:
        n1=1
        print(n1*100+n2*10+n3)
    elif N==2 and n2==0:
        n2=1
        print(n1*100+n2*10+n3)
    else:
        print(n1*100+n2*10+n3)