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

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 n1==0 and n2==0:
        if N==3:
            n1=1
        elif N==2:
            n2=1
        print(n1*100+n2*10+n3)
    elif n1==0:
        else:
            print(n2*10+n3)
    else:
        if N==3 and n1==0:
            n1=1
        elif N==2 and n2==0:
            n2=1
        print(n3+n2*10+n1*100)