N,M = map(int,input().split())
sc = []
falseFlag = 0
for i in range(M):
    a,b = map(int,input().split())
    sc.append([a,b])
    if a==1 and b==0:
        falseFlag = 1
        
if M>3:
    falseFlag = 1

sc.sort()
item = sc[0]
for i in range(1,M):
    if item[0] == sc[i][0] and item[1] != sc[i][1]:
        falseFlag = 1
        
if falseFlag==1:
    print(-1)
else:
    S = ''
    for i in range(1,N):
        sc.append([i+1,0])
    counter = 1
    while counter<=N:
        checker = []
        for i in range(len(sc)):
            if sc[i][0] == counter:
                checker.append(sc[i][1])
        S = S+max(checker)
        counter+=1
    print(S)