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

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

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))