import sys
n,m=map(int,input().split())
s=[]
c=[]
for i in range(m):
    st,ct=map(int,input().split())
    s.append(st)
    c.append(ct)
ans=[[0,0] for i in range(n)]
for i in range(m):
    if s[i]==1 and c[i]==0 and n>=2:
        print(-1)
        sys.exit()
    if ans[s[i]-1][1]==0:
        ans[s[i]-1][0]=c[i]
        ans[s[i]-1][1]=1
    else:
        if ans[s[i]-1][0] != c[i]:
            print(-1)
            sys.exit()
if ans[0][0]==0 and n>=2:
    ans[0][0]=1
ansn=0
for i in range(n):
    ansn+=ansn[i][0]*10**(n-i-1)
print(ansn)
        
        