num = {}
n, m = input().split(' ')
n = int(n)
m = int(m)
flag = 1

for _ in range(m):
  s, c = input().split(' ')
  s = int(s)
  c = str(c)
  if s in num and num[s] != c and num[s] != -1:
    flag = -1
    break
  elif s not in num:
    if s > flag:
      if s != 1 and flag == 1:
        flag += 1
        num[1] = 1
      for i in range(flag, s):
        num[i] = -1
    flag = s + 1
    num[s] = c
result = ""
if flag == -1:
  result = -1
else:
  l = num.values()
  l = [str(0) if i == -1 else i for i in l]
  result = "".join(l)
print(result)
     
  
  
 