N,M = map(int, input().split())
ans = 0
S = [""]*N
for _ in range(M):
  s, c = map(int,input().split())
  else:
    if S[s-1] == "" or S[s-1] == c:
      S[s-1] = c
    elif S[s-1] != "" and S[s-1] != c:
      print(-1)
      exit(0)
if N == 3:
  if S[0] == "":
    S[0] = 1
  if S[0] = 0:
    print(-1)
    exit(0)
  if S[1] == "":
    S[1] = 0
  if S[2] == "":
    S[2] = 0
  print(S[0],end="")
  print(S[1],end="")
  print(S[2])
elif N == 2:
  if S[0] == "":
    S[0] = 1
  if S[0] == 0:
    print(-1)
    exit(0)
  if S[1] == "":
    S[1] = 0
  print(S[0],end="")
  print(S[1],end="")
elif N == 1:
  if S[0] == "":
    print(0)
