N, M=map(int, input().split())

S=[list(map(int, input().split())) for i in range(M)]

num=["a"]*N
ans=True
for s in S:
  if (num[s[0]-1]!="a") and (num[s[0]-1]!=s[1]):
    ans=False
    break
  else:
    num[s[0]-1]=s[1]
    
if num[0]==0:
  ans=False
    
if ans:
  for i in range(N):
    if num[i]=="a":
      print(1, end="")
    else:
      print(num[i], end="")
else:
  print(-1)
  
         