import sys
input = sys.stdin.readline
def solve():
  n,m = (int(i) for i in input().split())
  query = []
  for i in range(m):
    s,c = (int(i) for i in input().split())
    query.append((s,c))
  ans = -1
  for i in range(1000):
    #search 0 to 999
    isanswer = True
    number = str(i)
    for s,c in query:
      if 10**(s-1) > int(number):
        isanswer = False
      elif number[s-1] != str(c):
        isanswer = False
    if isanswer:
      print(i)
      exit()
  print(ans)
solve()