n,m=map(int,input().split(" "))
g=[]
t=[]
sac=0
for i in range(n):
  g.append("0")
  t.append("")
for j in range(m):
  s,c=map(int,input().split(" "))
  if(g[s-1]!=str(c) and t[s-1]==""):
    g[s-1]=str(c)
    t[s-1]="T"
  if(g[s-1]!=str(c) and t[s-1]!=""):
    sac=1
  if(s==1 and c==0):
    sac=1
    op=1
if(t[0]=="" and len(g)!=1 and sac==0):
  g[0]="1"
if(op==1):
  sac=0
str_g = "".join(g)

if(sac==0 and g[0]!="0"):
  print(str_g)

elif(sac==0 and len(g)==1):
  print("0")
else:
  print("-1")