n,m = map(int,input().split())
ans = 10**(n-1)
sl = []
cl = []
for i in range(m):
  s,c = map(int,input().split())
  sl.append(s)
  cl.append(c)
for i in range(m-1):
  for j in range(i+1,m):
    if(sl[i]==sl[j])and(cl[i]!=cl[j]):
      ans = -1
      break
    if(sl[i]==1)and(cl[i]==0):
      ans = -1
      break
if(sl[m-1]==1)and(cl[m-1]==0):
  ans = -1
if(ans == -1):
  print(ans)
else:
  for i in range(m):
    if(sl[i]==1):
      ans += 10**(n-sl[i])*(cl[i]-1)
    else:
      10**(n-sl[i])*(cl[i]-1)
  print(ans)
        