import sys
n,m=map(int,input().split())
s=[]
c=[]
for i in range(m):
    ts,tc=map(int,input().split())
    ts-=1
    s.append(ts)
    c.append(tc)

if n==1:
    ans=min(c)
    for i in range(m):
        if ans!=c[i]:
            print(-1)
            sys.exit()

if n!=1:
    ans=[1]+[0 for i in range(n-1)]
    for i in range(m):
        if s[i]==0 and c[i]==0:
            print(-1)
            sys.exit()
        ans[s[i]]=max(ans[s[i]],c[i])


    for i in range(m):
        if ans[s[i]]!=c[i]:
            print(-1)
            sys.exit()
    for i in range(n):
        print(ans[i],end="")

