N,M=map(int, input().split())

sum = 1

s = []
c = []
n=0
for i in range(M):
  si,ci=map(int, input().split())
  sum = sum * ( (si-1)**2+ci**2 )
  if si in s:
    if(ci!=c[s.index(si)]):
      sum = 0
      n = n + ci * 10 ** (N-si)
  else:
    n = n + ci * 10 ** (N-si)
  s.append(si)
  c.append(ci)

if 1 not in s:
  n = n + 10 ** (N-1)
  
if sum == 0:
  print(-1)
else:
  if M == 0:
    if N == 1:
      print(0)
    else:
      print(10**(N-1))
  else: 
    print(n)