n,m=map(int,input().split())
res=[set() for i in range(n)]
num=""
flag=False
for i in range(m):
  si,ci=map(int,input().split())
  if n!=1 and si==1 and ci==0:
    flag=True
    break
  res[si-1].add(ci)
for i in range(n):
  if len(res[i])>1 or flag:
    print(-1)
    break
  elif len(res[i])==1:
    num+=str(res[i].pop())
  elif i==0 and len(res[i])==0:
    num+=str(1)
  elif i!=0 and len(res[i])==0:
    num+=str(0)
else:
  print(num)
  