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

#print(N)
#print(M)

str = [0] * N
ans = []

for i in range(M):
  line = lines.pop(0).split(' ')
#  print(line)
  s = int(line[0])
  c = int(line[1])
#  print(s)
#  print(c)
  str[s-1] = c
  if N == 3:
    ret = int(str[0])*100 + int(str[1])*10 + int(str[2])
    if int(str[2]) > 0 or (s==3 and c==0):
      ans.append(ret)
  elif N == 2:
    ret = int(str[0])*10 + int(str[1])
    if int(str[1]) > 0 or (s==2 and c==0):
        ans.append(ret)
  else:
    ret = int(str[0])
    ans.append(ret)
    
for obj in ans[:]:
  if (obj / (10**(N-1))) < 1:
    ans.remove(obj)

if not ans:
  print('-1')
else:
  print(min(ans))
