n,m = map(int, input().split())

sc = set([tuple(map(int, input().split())) for _ in range(m)])
ans = 0
h = []

for x,y in sc:
  if x == 1 and y == 0:
    print(-1)
    exit()
  if x in h:
    mini_b = 10**18
    for a,b in sc:
      if x == a:
        mini_b = min(mini_b, b)
    if mini_b > y:
        ans -= mini_b * (10 ** (n-x))
        ans += y * (10 ** (n-x))
  ans += y * (10 ** (n-x))
  h.append(x)

if ans < 10**(n-1):
  ans += 10**(n-1)
print(ans)