import strutils,sequtils
var
  I=stdin.readLine.split.map parseInt
  A,B=newSeq[int](I[0]+1)
  x=false
  S,C=0
for i in 1..I[0]:
  (S,C)=stdin.readLine.split.map parseInt
  if B[S]<1:
    A[S]=C
  else:
    x=x or A[S]!=C
  B[S]=1
if I[0]>1:
    A[1]+=1-B[1]
    x=x or A[1]<1
if x:
  echo -1
else:
  for a in A[1..^1]:
    stdout.write a