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 = ""

    # for a in range(len(A)):
    #     if A[a][0] == 1:
    #         flg1 = True
    #     elif A[a][0] == N:
    #         flg2 = True

    # if flg1 == False or flg2 == False:
    #     return -1

    A.sort()
    #print(A)

    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
    if flg1 == False:
        return -1
    else:
        for n in range(N):
            min = 10
            for a in range(len(A)):
            #    print("n",n+1,"A[a][0]",A[a][0],"A[a][1]",A[a][1],"min",min)
                if A[a][0] == n+1:
                    min = A[a][1]
            if min != 10:
                number += str(min) 
            else:
                number += "0"

        number2 = int(number)
        number3 = str(number2)
        if len(number3) == N:
            return number3
        else:
            return -1


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