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

tmp = ["0" for i in range(n)]
digit = [[] for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  digit[int(s)-1].append(c)
for i in range(n):
  if len(digit[i]) == 0:
    digit[i].append("0")
  
ans = []
if n == 3:
  for i in range(len(digit[0])):
    for j in range(len(digit[1])):
      for k in range(len(digit[2])):
        t = int(digit[0][i] + digit[1][j]+digit[2][k])
        if len(str(t)) == n:
          ans.append(t)  
if n ==2:
  for i in range(len(digit[0])):
    for j in range(len(digit[1])):
      t = int(digit[0][i] + digit[1][j])
      if len(str(t)) == n:
        ans.append(t)
if n == 1:
  for i in range(len(digit[0])):
    t = int(digit[0][i])
    ans.append(t)
    
if len(ans) == 0:
  print(-1)
else:
  print(min(ans))
  
