import sys

InputValue = input().split(' ')
N = int(InputValue[0])
M = int(InputValue[1].strip('\n'))

##print(type(N),type(M))

S=[]
C=[]

if 1<=N<=3 and 1<=M<=5:
    for Count in range(M):
        InputValue = input().split(' ')
        if 1<=int(InputValue[0])<=N and \
            0<= int(InputValue[1]) <=9:
            S.append (int(InputValue[0]))
            C.append (int(InputValue[1]))
        else:
            print('-1')
            sys.exit()
else:
    print('-1')
    sys.exit()

for Count in range(M):
    if N>1 and S[Count]==1 and C[Count]==0:
        print('-1')
        sys.exit()

Result=[0]*N

def CheckSameDigit_DifferentValue(StartIndex,M,Result):
    for Count in range(StartIndex,M):
        if Count != M-1:
            if S[StartIndex] == S[Count+1] and \
               C[StartIndex]!=C[Count+1]:
                print('-1')
                sys.exit()

    Result[S[StartIndex]-1]= C[StartIndex]

for Count in range(0,M):
    CheckSameDigit_DifferentValue(Count,M,Result)

if N == 1:
    print(Result[0],sep='')
elif N == 2 and Result[0]!=0:
    print(Result[0],Result[1],sep='')
elif N == 3 and  Result[0]!=0:
    print(Result[0],Result[1],Result[2],sep='')
else:
    print('-1')