n,m=map(int,input().split())
ans=[set()for i in range(n)]
for i in range(m):
    s,c=map(int,input().split())    
    ans[s-1].add(c)
f=1
an=''
#print(ans)
for i in ans:
    if len(i)>1:
        f=0
        break
    if len(i)==0:
        an+='1'
    else:
        an+=str(i.pop())
if not f:
    print(-1)
else:
    if an[0]=='0':
        print(-1)
    else:    
        print(an)

    
    
    
    