n,m=map(int,input().split())
a=['-1' for i in range(n)]

if n==1 and m==0:
    print(0)
    exit()
    
for i in range(m):
    s,c=map(int,input().split())
    if s>n:
        print(-1)
        exit()
        
    if a[s-1]=='-1' or str(c)==a[s-1]:
        a[s-1]=str(c)
    else:
        print(-1)
        exit()
    
    if a[0]=='0':
        print(-1)
        exit()

if a[0]=='-1':
    a[0]='1'
   
 

for i in range(n):
    if a[i] == '-1':
        a[i]='0'
        
print(''.join(a))   
