n,m=map(int,input().split())
l=[10]*n
for i in range(m):
  s,c=map(int,input().split())
  if c<l[s-1]:
    l[s-1]=c
for i in range(len(l)):
  if l[i]==10:
    l[i]=str(1)
  else:
    l[i]=str(l[i])
ans=int("".join(l))
if len(str(ans))!=n and ans!=0:
  print(-1)
else:
  print(ans)