n,m=map(int,input().split())
a=[]
for j in range(n):
  a+="x"
y=0
for i in range(m):
  s,c=map(int,input().split())
  if a[s-1]!="x" and a[s-1]!=c:
    print("-1")
    y+=1
    break
  if a[s-1]=="x":
    if c==0:
      if s==1:
        print("-1")
        y+=1
        break
      else:
        a[s-1]=c
    else:
      a[s-1]=c
if y!=1:
  for j in range(m):
    if a[j]=="x":
      a[j]="0"
    print(a[j],end="")