n, m = map(int, input().split())
l = []
for _ in range(m):
    s = list(map(int, input().split()))
    if s in l:
        continue
    l.append(s)
m = len(l)

for i in range(m-1):
    for j in range(i+1, m):
        if l[i][0]==l[j][0] and l[i][1]!= l[j][1]:
            print(-1)
            exit()

for x,y in l:
    if x==1 and y==0 and n!=1:
        print(-1)
        exit()

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

if n==1:
    print(l[0][1])

res = 0
if n==2:
    for i in l:
        if i[0]==1:
            res += i[1]*10
        if i[0]==2:
            res += i[1]
    print(res)

if n==3:
    for i in l:
        if i[0]==1:
            res += i[1]*100
        if i[0]==2:
            res += i[1]*10
        if i[0]==3:
            res += i[1]
    print(res)
