N,M=map(int,input().split())
n=[0 for i in range(N)]
F=0
for t in range(M):
    s,c=map(int,input().split())
    if n[s-1]==0 or n[s-1]==c:
        n[s-1]=c
    else:
        F=1
        break
ans=''
for x in n:
    ans+=str(x)
print(int(ans) if F==0 and ans!='000' else -1 if ans=='000' else -1)
    