n,m=map(int,input().split())
s,c=[],[]

for _ in range(m):
    a,b=[int(i) for i in input().split()]
    a-=1
    s.append(a)
    c.append(b)
        
for i in range(10**(n-1),10**n):

    f=True    
    for j in range(m):
       if str(i)[s[j]] != str(c[j]):
            f=False
          
    if f==True:
        print(i)
        exit()

print(-1)