N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = map(int, input().split())
    
A = []
x = 0

for i in range(M):
  if s[i] == 1 and c[i] == 0:
    x = 1
  for j in range(i+1,M):
    if s[i] == s[j] and c[i] != c[j]:
      x = 2
      
import numpy as np
from functools import reduce
B = np.zeros(N)
B[0] = 1

if M == 0:
  for i in range(M):
    B[s[i]-1] = c[i]
  ans = reduce( lambda a,b:10*a+b, B)
  print(round(ans))

elif N == 1 and max(s) == 1 and max(c) == 0:
  print(0)

elif x == 1 or x == 2:
  print("-1")
  
else:
  for i in range(M):
    B[s[i]-1] = c[i]
  ans = reduce( lambda a,b:10*a+b, B)
  print(round(ans))