a = -1
n,m = map(int, input().split())
s_and_c = [tuple(map(int,input().split())) for i in range(m)]
s = []
c = []
l = [0]*m
for t in s_and_c:
  l[t[0]-1] = t[1]
for _ in s_and_c:
  s.append(_[0])
  c.append(_[1])
if max(s) == n and l[0] != 0:
  a = "".join([str(i) for i in l])
else:
  pass
print(a)