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


    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 and A[a][1]<min:
                min = A[a][1]
        if min != 10:
            number += str(min) 
        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)