N,M=map(int,input().split())
numbers=[' ',]*N
kotae=0
for a in range(M):
    suuji=[]
    s,c=input().split()
    if numbers[int(s)-1]==' ':
        numbers[int(s)-1]=c
    else:
        if numbers[int(s)-1]==c:
            continue
        else:
            print('-1')
            kotae+=1
            break

for a in range(N):
    if numbers[a]==' ':
        numbers[a]=0
if N>=2:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
            if numbers[0] == 0:
                del numbers[0]
if kotae==0:
    if len(numbers)!=N:
        print('-1')
    else:
       moji=''
       for a in numbers:
           moji+=str(a)
       print(moji)
