n,m=( int(x) for x in  input().split())
#print(n,m)
st=[]
for i in range(n):
  st.append('a')
#print(st)
ng=0
for i in range(m):
  s,c=(int(x) for x in input().split())
  if st[s-1]=='a':
    st[s-1]=str(c)
  elif st[s-1]==str(c):
    pass
  else:
    ng=ng+1
#print(st,ng)
if ng>0:
  print(-1)
else:
  for i in range(n):
#    print(n,i,st[i])
    if i==0:
      if st[0]=='a':
        st[0]='1'
        
    if st[i]=='a':
      st[i]='0'
#  print(st)
  ans=0
  for i in range(n):
  	ans+= 10**(2-i) * int(st[i])
  if n>1:
    if st[0]=='0':
      print(-1)
    else:
      print(ans)
  else:
    print(ans)