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