n,m=map(int,input().split())
d=[0]*(n+1)
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        if n==1:
            pass
        else:
            print(-1)
            exit()
            
    if d[s]==c:
        continue
    elif d[s]!=c and d[s]==0:
        d[s]=c
    else:
        print(-1)
        exit()
print("".join(list(map(str,d[1:]))))
