n,m=[int(_) for _ in input().split()]


ans=[-1 for i in range(n)]

for i in range(m):
  s,c=[int(_)for _ in input().split()]
  if (ans[s-1]!=-1 and ans[s-1]!=c)or (s==1 and c==0):
    print(-1)
    exit()
  else:
    ans[s-1]=c

ans[0]=max(1,ans[0])
ans.reverse()
t=0
d=1

for i in range(n):
  t+=max(0,ans[i])*d
  d*=10
#print(ans)
print(t)