N,M=map(int,input().split())
A=[0]*N
for _ in range(M):
    s,c=map(int,input().split())
    if A[s-1]>c or A[s-1] == 0:
        A[s-1]=c

try:
    if A.index(0)==0:
        answer=-1
except:
    answer=int(''.join([str(a) for a in A]))

print(answer)
