n,m=map(int,input().split())
SC=[list(map(int,input().split())) for _ in range(m)]

if n==0:
  print(0)
  exit()
ans=[0]*n
ans[0]=1
for s,c in SC:
  if ans[s-1]==0:
    ans[s-1]=c
  else:
    if ans[s-1]!=c:
      print(-1)
      exit()
if ans[0]==0:
  ans[0]=1
print(*ans,sep='')