n,m=map(int,input().split())
from collections import defaultdict
d = defaultdict(int)
for i in range(m):
  a,b=map(int,input().split())
  if d[a] != 0 and d[a] != b:
    print(-1)
    exit()
  d[a] = b
flag = False; pos = 0
for i in range(1,n+1):
  if d[i] != 0: 
    pos = i
    flag = True
    break
if not flag:
  print(-1); exit()
for i in range(pos,n+1):
  print(d[i], end='')