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 s==1 and t==0:
        print(-1)
        exit()
    elif l[s-1]==0 or l[s-1]==t:
        l[s-1]=t
    else:
        print(-1)
        exit()
ans=map(str,l)

print(''.join(ans))