n,m=list(map(int,input().split()))
ans=[set() for _ in range(n)]
for i in range(m):
    s,c=list(map(int,input().split()))
    s-=1
    ans[s].add(c)
cal=[float("inf") for _ in range(n)]
if n>1 and (0 in ans[0]):
    print(-1)
    exit()
for i in range(n):
    if len(ans[i])>1:
        print(-1)
        exit()
    if len(ans[i])==1:
        cal[i]=str(list(ans[i])[0])
    elif len(ans[i])==0:
        if i==0:
            cal[i]=str(1)
        else:
            cal[i]=str(0)
print("".join(cal))