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

D=[-1]*3
ans=True

for s,c in S:
    if D[s-1] == -1:
        D[s-1]=c
    else:
        if D[s-1] != c:
            ans=False
if D[N-1]==0: ans=False

t=[i if i != -1 else 0 for i in D]

print(''.join(map(str,t)) if ans else -1)