n,m=map(int, input().split())

if m == 0:
    if n == 1: print("0")
    if n == 2: print("10")
    if n == 3: print("100")
    exit()

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

tmp1 = 0
tmp10 = 0
tmp100 = 0

if len(set(c[0])) > 1:
    print("-1")
    exit()
elif len(set(c[0])) == 1:
    tmp100 = c[0][0]
else :
    tmp100 = 1

if len(set(c[1])) > 1:
    print("-1")
    exit()
elif len(set(c[1])) == 1:
    tmp10 = c[1][0]
else :
    tmp10 = 0

if len(set(c[2])) > 1:
    print("-1")
    exit()
elif len(set(c[2])) == 1:
    tmp1 = c[2][0]
else :
    tmp1 = 0

if tmp100==0:
    print("-1")
    exit()

print(tmp1+tmp10*10+tmp100*100)