n,m=map(int,input().split())
q=[]
for i in range(m):
  q+=[list(map(int,input().split()))]

if n==1:
  ans=0
  for j in range(m):
    s,c=q[j]
    if s!=1:
      ans=-1
      break
    if c!=0:
      ans=-1
      break
else:
  ans=-1
  

for i in range(1,10**n):
  k=1
  for j in range(m):
    s,c=q[j]
    s=n-s
    if i//(10**s)==0:
      k=0
      break
    if i//(10**s)%10!=c:
      k=0
      break
  if k:
    ans=i
    break
    
print(ans)