N, M = map(int, input().split())
s = []
c = []
a = [10, 10, 10]
ans = 0

for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)
    
if 3 - (N - 1) not in s:
  print(-1)
else:
  for i in range(M):
    if c[i] < a[s[i] - 1] and c[i] != 0:
      a[s[i] - 1] = c[i]
      
  for i in range(3):
    if a[i] == 10:
      a[i] = 0
  
  if N == 1:
    print(a[2])
  elif a[3 - N] == 0:
    print(-1)
  else:
    for i in range(N):
      ans = ans + a[2 - i] * (10 ** i)
    print(ans)