import sys
import math
lines = sys.stdin.readlines()
line1 = lines.pop(0).split(' ')
#print(line1)
N = int(line1[0])
M = int(line1[1])
#print(N)
#print(M)

if M == 0:
  print('-1')
  sys.exit()

#初期化
str = [10] * N
#print(str)

for i in range(M):
  line = lines.pop(0).split(' ')
#  print(line)
  s = int(line[0])
  c = int(line[1])
#  print(s)
#  print(c)
#  print(str[s-1])
  if str[s-1] > c:
    str[s-1] = c

#print(str)
str = [0 if i == 10 else i for i in str]
#print(str)
if N == 3:
  ret = (int(str[0])*100 + int(str[1])*10 + int(str[2])) if int(str[0]) > 0 else -1
elif N ==2:
  ret = (int(str[0])*10 + int(str[1])) if int(str[0]) > 0 else -1
elif N ==1:
  ret = int(str[0])

print(ret)
