N,M = map(int,input().split())
a1 = set()
a2 = set()
a3 = set()
for i in range(M):
  s,c = map(int,input().split())
  if s == 1:
    a1.add(c)
  elif s == 2:
    a2.add(c)
  elif s == 3:
    a3.add(c)
if len(a1)>1 or len(a2)>1 or len(a3)>1:
  print(-1)
else:
  a1 = list(a1)
  a2 =list(a2)
  a3 = list(a3)
  T = [0,0,0]
  if len(a1) == 1:
    T[0] = a1[0]
  if len(a2) == 1:
    T[1] = a2[0]
  if len(a3) == 1:
    T[2] = a3[0]
  k = int(str(T[0])+str(T[1]) + str(T[2]))
  if len(str(k)) != N:
    print(-1)
  else:
    print(k)
  