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

s = [0]*m
c = [0]*m

for k in range(m):
    s[k], c[k] = list(map(int, input().split()))

for l in range(m):
    if n == 1:
        if s[l] != 1:
            print(-1)
            exit()
    elif n == 2:
        if s[l] == 3:
            print(-1)
            exit()
    elif n == 3:
        if s[l] == 1 and c[l] == 0:
            print(-1)
            exit()

if n == 1:
    kaishi = 1
    owari = 10
elif n == 2:
    kaishi = 10
    owari = 100
elif n == 3:
    kaishi = 100
    owari = 1000

for num in range (kaishi, owari):
    seigo = 1
    for i in range(m):
        if s[i] == 3:
            if num%10 == c[i]:
                continue
            else:
                seigo = 0
        if s[i] == 2:
            if (num//100) == 0 and (num%100)//10 == 0:
                seigo = 0 
            elif (num%100)//10 == c[i]:
                continue
            else:
                seigo = 0
        if s[i] == 1:
            if c[i] == 0:
                seigo = 0
            elif (num//100) == c[i]:
                continue
            else:
                seigo = 0

    if seigo == 1:
        print(num)
        exit()
        
print(-1)



