n,m = map(int,input().split())
a = [0]*n
for i in range(m):
  t,s = map(int,input().split())
  if a[t] == 0 :
    a[t] = s
  else:
    if not a[t] == s:
      print('-1')
      exit()

if sum(a) == 0:
  print('-1')
  exit()
for i in range(n):
  tmp += str(a[i])
print(int(tmp))