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

num = []
for i in range(N) :
  num.append([0])

sc = []
for i in range(M) :
  sc.append(list(map(int, input().split()))) 

ans = ""

for n in sc :
  if n[1] not in num[n[0]-1] :
    num[n[0]-1].append(n[1])

if N >= and [1, 0] in sc :
  print('-1')
  sys.exit()
elif N >= 2 and num[0] == [0] :
  num[0].append(1)

for m in num :
  if len(m) >= 3 :
    print('-1')
    sys.exit()

if len(num[0]) == 1 :
  print('-1')
  sys.exit()
else :
  for l in range(N) :
    ans = ans + str(max(num[l]))

print(ans)