isExists = True
n,m = list(map(int,input().split()))
n1,n2,n3 = -1,-1,-1
for i in range(m):
  si,ci = list(map(int,input().split()))
  if si == 1:
    if n1 == -1 or n1 == ci:
      n1 = ci
    else:
      #print('p1')
      isExists = False
  elif si == 2:
    if n2 == -1 or n2 == ci:
      n2 = ci
    else:
      #print('p2')
      isExists = False
  elif si == 3:
    if n3 == -1 or n3 == ci:
      n3 = ci
    else:
      #print('p3')
      isExists = False
if (n == 2 or n == 3) and n1 == 0:
  #print('p4')
  isExists = False
if n1 == -1:
  n1 = 1
if n2 == -1:
  n2 = 0
if n3 == -1:
  n3 = 0
if isExists == True:
  if n == 1:
    print(n3)
  elif n == 2:
    print(str(n2)+str(n3))
  elif n == 3:
    print(str(n1)+str(n2)+str(n3))
else:
  print(-1)