import sys

n,m = input().split()
n,m = [int(n), int(m)]
num = 0
flag = 0
s = []
c = []

for i in range(m):
  s_i,c_i = input().split()
  s_i,c_i = [int(s_i), int(c_i)]
  flag = 0
  if s_i == 1 and c_i == 0:
    print(-1)
    sys.exit()
    
  for j in range(i):
    if s[j] == s_i and c[j] != c_i:
      print(-1)
      sys.exit()
    elif s[j] == s_i and c[j] == c_i:
      flag = 1
      
  s.append(s_i)
  c.append(c_i)
  if flag == 1:
    continue
  
  num += c_i * pow(10, n-s_i)
  
print(num)