n,m = input().split()
m = int(m)
s =  [list(map(int,input().split())) for i in range(m)]
brk =0
n = int(n)
nl = [0]*n
chk = [0]*n
for i in s:
    if chk[i[0]-1] >0 and nl[i[0]-1] != i[1]:
        brk = 1
        break
    elif i[0] == 1 and i[1] ==0:
        brk = 1
        break
    else:
        nl[i[0]-1] = i[1]
        chk[i[0]-1] += 1

if brk == 1: print("-1")
elif nl[0] == 0:
  nl[0] =1
  L=[str(a) for a in nl]
  #print(L)
  fn = int("".join(L))
  print(fn)

else:
  L=[str(a) for a in nl]
  #print(L)
  fn = int("".join(L))
  print(fn)