n,m=map(int,input().split())
s=[]
c=[]
ans=0
no=False
mm=True
for i in range(m):
    ss,cc=map(int,input().split())
    for q in range(i):
        if s[q]==ss:
            if c[q]!=cc:
                no=True
                break
            else:
                ans-=cc*(10**(n-ss))

    s.append(ss)
    c.append(cc)

    ans+=cc*(10**(n-ss))
    if ss==1:
        mm=False
        if cc==0:
            no=True


if mm:
    ans+=10**n

if no:ans=-1

print(ans)