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 and len(num)>1:
  ans=False
    
if ans:
  if len(num[0])==1:
    if num[0]=="a":
      print(0)
    else:
      print(num[0])
  else:
    for i in range(N):
      if num[i]=="a":
        if i==0:
          print(1, end="")
        else:
          print(0, end="")
      else:
        print(num[i], end="")
else:
  print(-1)
  