a,b=[int(i) for i in input().split()]
s=['*']*a
flag=0
l=''
for i in range(b):
    n,m=[int(i) for i in input().split()]
    if(s[n-1]!='*' and str(m)!=s[n-1]):
        flag=1
        break
    else:
        s[n-1]=str(m)
if(s[0]=='*'):
    s[0]='0'
if(s[1]=='*'):
    s[1]='0' 
if(s[2]=='*'):
    s[2]='0'
l=s[0]+s[1]+s[2]
l=int(l)
if(flag>0 or len(str(l))!=n):
    print(-1)
else:
    print(l)