import numpy as np

a = list(map(int,input().split()))
a = np.array(a)
N = int(a[0])
M = int(a[1])
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)
keta = []
for i in range(N):
    keta.append(int(0))

kainashi = 0
wa = 0
for i in range(M):
    keta[s[i]-1] = i
    wa = wa + c[i]
    if N > 1:
        if s[i] == 1:
            if c[i] == 0:
                kainashi = 1
    for j in range(M):
        if s[i] == s[j]:
            if c[i] != c[j]:
                kainashi = 1

if int(wa) == 0:
    if int(N) == 1:    
        print(0)
else:
    if kainashi == 1:
        print(-1)
    else:
        kai = 0
        for i in range(N):
            if keta[i] > 0:
                kai = kai + (10**(2-i))*int(c[keta[i]]) 
                if kai < 10**(N-1):
                    kai = kai + 10**(N-1)
        print(int(kai))