N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

D=[0]*3
ans=True

for s,c in S:
    if D[s-1] == 0:
        D[s-1]=c
    else:
        if D[s-1] != c:
            ans=False
if D[N-1]==0: ans=False
    
print(''.join(map(str,D)) if ans else -1)