n,m=map(int,input().split())
s=[]
d={}
flag=0
for i in range(n):
  s.append(0)
  
for i in range(m):
  a,b=map(int,input().split())
  if a not in d:
    d[a]=b
  elif d[a]!=b:
    flag=1
    break
  s[a-1]=b

q=str()
#print(flag,s)
if flag==0 and s[0]!=0:
  for i in range(n):
    q+=str(s[i])
  print(q)
else:
  print(-1)
  
  
  