n,m=map(int,input().split())
a=[0]*n
count=0
b=[]
d=[]
for i in range(m):
  s,c=map(int,input().split())
  b.append(s)
  d.append(d)
  if a[s-1]==0 or c:
    a[s-1]=c  
  else:
    print("-1")
    exit()
    
for i in range(m):
  for j in range(i,m-1):
    if b[i]==b[j]:
      if d[i]!=d[j]:
        print('-1')
        exit()
  
if a[0]==0 and n!=1:
      print("-1")
      exit()
      
for i in range(len(a)):
  print(a[i],end='')