output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: N, M = map(int, input().split())
  S = []
  C = []
  for i in range(M):
      temp1, temp2 = map(int, input().split())
      S.append(temp1)
      C.append(temp2)
  
  Flag = True
  temp = [-1, -1, -1]
  for i in range(M):
      if S[i] == 3:
          if temp[2] == -1:
              temp[2] = C[i]
          else:
              if temp[2] == C[i]:
                  next
              else:
                  Flag = False
  
  for i in range(M):
      if S[i] == 2:
          if temp[1] == -1:
              temp[1] = C[i]
          else:
              if temp[1] == C[i]:
                  next
              else:
                  Flag = False
  
  for i in range(M):
      if S[i] == 1:
          if temp[0] == -1:
              temp[0] = C[i]
          else:
              if temp[0] == C[i]:
                  next
              else:
                  Flag = False
  
  a = ""
  if Flag == False:
      print(-1)
  elif temp[0] == 0:
      print(-1)
  elif temp[2] == -1:
      if temp[1] == -1:
          print(temp[0])
      elif temp[0] == -1:
          print(int(str(1) + str(temp[1])))
      else:
          if temp[0] == 0:
              print(-1)
          else:
              print(int(str(temp[0]) + str(temp[1])))
  else:
      if temp[0] == -1 and temp[1] == -1:
          print(temp[2])
      elif temp[0] == -1 and temp[1] != -1:
          if temp[0] == 0:
              print(-1)
          else:
              print(int(str(temp[1]) + str(temp[2])))
      elif temp[0] != -1 and temp[1] == -1:
          if temp[0] == 0:
              print(-1)
          else:
              print(int(str(temp[0]) + str(0) + str(temp[2])))
      else:
          if temp[0] == 0:
              print(-1)
          else:
              print(int(str(temp[0]) + str(temp[1]) + str(temp[2])))
  
problem_description: Statement
  
  Takahashi wants to print a document with N pages double-sided, where two pages
  of data can be printed on one sheet of paper.
  
  At least how many sheets of paper does he need?
samples: [{"input": "5", "output": "3\n    \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n    \n\n* * *"}, {"input": "100", "output": "50"}]