n,m=map(int,input().split())
l=list(0 for _ in range(m))
for i in range(m):
    s,t=map(int,input().split())
    if l[s-1]==0 or l[s-1]==t:
        l[s-1]=t
    
ans=map(str,l)

print(''.join(ans) if l[0]!=0 else -1)