f=lambda:map(int,input().split())
n,m=f()
l=[0]*n
b=[0]*n
if n>1: l[0]=1
for _ in range(m):
  s,c=f()
  s-=1
  if b[s] and l[s]!=c or n>1 and s==c==0:
    print(-1)
    exit()
  l[s]=c
  b[s]=1
print(*l,sep='')