n,m=map(int,input().split())
S=[]
for i in range(m):
    s=list(map(int,input().split()))
    S.append(s)
SS=sorted(S)
L=[[] for i in range(n)]
for i in range(m):
    L[SS[i][0]-1].append(SS[i][1])
if L[0]==[]:
    print(-1)
    exit()
R=[10]*n
for i in range(n):
    if len(set(L[i]))==1:
        R[i]=list(set(L[i]))[0]
    elif L[i]==[]:
        R[i]=0
    else:
        print(-1)
        exit()
if R[0]==0:
    if n==1:
        print(0)
    else:
        print(-1)
        exit()
else:
    print(''.join(map(str,R)))