n,m = map(int,input().split())
a = [list(map(int,input().split())) for raw in range(m)]
b = sorted(a)
t = 0
u = -1
ans = 0
wer = 0
for c in b:
  k = int(c[0])
  s = int(c[1])
  if k != t:
    ans += s*(10**(n-k))
  if k == t and s != u:
    wer += 1
  t = k
  u = s
if wer == 0:
  print(ans)
else:
  print(-1)