n,m=map(int,input().split())
x=[]
for _ in range(n):
    x.append([])

for _ in range(m):
    s,c=map(int,input().split())
    x[s-1].append(c)
ans=''
for i in range(n):
    if len(set(x[i]))>=2:
        ans='-1'
        break
    if len(x[i])==0 and i==0:
        ans+='1'
    elif len(x[i])==0 and i!=0:
        ans+='0'
    else:
        ans+=str(x[i][0])
if 0 in x[0]:
    if i==1:
        ans='0'
    else:
        ans='-1'
print(int(ans))