n,m=map(int,input().split())
sc=[]
for i in range(m):
  q=list(map(int,input().split()))
  if q not in sc:
    sc.append(q)
slist=[i[0] for i in sc]
if len(slist)!=len(set(slist)):
  print("-1")
  exit()
if n!=1 and [1,0] in sc:
  print(-1)
  exit()
if n==1 and sc == [[1,0]]:
  print(0)
  exit()

sc.sort()
num=""
k=0
sc.append(n+1)
for i in range(1,n+1):
  if sc[k][0]==i:
    num += str(sc[k][1])
    k+=1
  else:
    if i==1:
      num+="1"
    else:
      num += "0"
print(int(num))