import sys
input = sys.stdin.readline
from collections import defaultdict,deque
#from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
sys.setrecursionlimit(10**6)
"""========main code==============="""

#t=ii()
t=1
for _ in range(t):
    n,m=ml()
    d=defaultdict(set)
    flag=0
    for i in range(m):
        x,y=ml()
        d[x].add(y)
        if(len(d[x])>1 or (x==1 and y==0)):
            flag=1
            
    f=0
    ans=[]
    for i in range(1,n+1):
        if(len(d[i])==0 and f==0):
            f=1
            ans.append('1')
        elif len(d[i])==0 and f==1:
            ans.append('0')
        else:
            for j in d[i]:
                if(j==0 and f==0):
                    ans.append('1')
                    f=1
                else:
                    ans.append(str(j))
                
    if(flag):
        print(-1)
    else:    
        print(int("".join(ans)))        
            