n,m = map(int,input().split())
st = set(range(0,10**n))

for _ in range(m):
    s,c = map(int, input().split())
    lst = list(range(0,10**n))
    st1 = set()
    if s==1 and c==0 and n != 1:
        st &= set()
    for i in range(0,10**n):
        x = i // 10**(n-s)
        if x % 10 == c:
            st1.add(i)
    st &= st1

lst = list(st)
lst.sort()
lst.append(-1)
print(lst[0])