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