n,m = (int(x) for x in input().split())
frg = 0
ls=[0]*m
lc=[0]*m
for i in range(m):
  ls[i],lc[i] = (int(x) for x in input().split())

if n == 1:
  if len(set(lc)) != 1:
    print(-1)
  else:
    print(lc[0])
  
else:
  for i in range(m):
    if ls[i] == 1:
      if lc[i] == 0:
        frg = 1

  if frg == 1:
    print(-1)
  else:
    A = [0]*n
    for i in range(n):
      ls_idx = [j for j, x in enumerate(ls) if x == i+1]
      if len(ls_idx)==1:
        A[i] = lc[ls_idx[0]]
      elif len(ls_idx)>1:
        lctmp = []
        for k in ls_idx:
          lctmp.append(lc[k])
        if len(set(lctmp))==1:
          A[i] = lc[ls_idx[0]]
        else:
          frg = 1
    if frg == 1:
      print(-1)
    else:
      if A[0] == 0:
        NA = '1'
      else:
        NA = str(A[0])
      for i in range(1,n):
        NA = NA + str(A[i])
      print(int(NA))