import re

def nyu():
    N,M  = map(int,input().split())
    if M != 0:
        A = [list(map(int,input().split())) for i in range(M)]
    else:
        A =[[0,0]]
    return N,M,A

def check(N,M,A):

    flg1 = True
    number = ""
    N1 = "*"
    N2 = "*"
    N3 = "*"

    A.sort()

    for a in range(len(A)-1):
        if A[a][0] == A[a+1][0] and A[a][1] != A[a+1][1]:
            flg1 = False
            break

    for a in range(len(A)):
        if A[a][0] == 1:
            N1 = str(A[a][1])
        elif A[a][0] == 2:
            N2 = str(A[a][1])
        elif A[a][0] == 3:
            N3 = str(A[a][1])
            
    if flg1 == False:
        return -1
    else:
        for n in range(1000):
            n_ans = str(n)
            n_ans = n_ans.zfill(3)
        #    if re.match(r"%S"% N1,n_ans[0:1])   and re.match(r"%S"% N2,n_ans[1:2]) and re.match(r"%S"% N3,n_ans[2:3]):
            if N1 == "*" or N1 == n_ans[0:1]:
                if N2 == "*" or N2== n_ans[1:2]:
                   if N3 == "*" or N3 == n_ans[2:3]:
                    n_ans_int = int(n_ans)
                    n_ans = str(n_ans_int)
                    if len(n_ans) == N:
                        return n_ans

    return -1


N,M,A = nyu()
print(check(N,M,A))