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

def check(N,M,A):

    flg1 = False
    flg2 = False
    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)
    A_ans =[[1,10],[2,10],[3,10]]


    for a in range(len(A)):
    #    print("n",n,"A[a][0]",A[a][0],"A[a][1]",A[a][1],"min",min)
        if A[a][0] == A_ans[0][0] and A[a][1]<A_ans[0][1]:
            A_ans[0][1] = A[a][1]
        elif A[a][0] == A_ans[1][0] and A[a][1]<A_ans[1][1]:
            A_ans[1][1] = A[a][1]
        elif A[a][0] == A_ans[2][0] and A[a][1]<A_ans[2][1]:
            A_ans[2][1] = A[a][1]

    for ans in range(len(A_ans)):
        if A_ans[ans][1] != 10:
            number += str(A_ans[ans][1])
        else:
            number += "0"

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





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