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

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