n,m=list(map(int,input().split()))
d=[-1]*4
for _ in range(m):
  s,c=list(map(int,input().split()))
  if d[s]!=-1 and d[s]!=c:
    print(-1)
    exit(0)
  d[s]=c
ans=0
for i in range(1,n+1):
  if d[i]==-1:d[i]=0
  ans=10*ans+d[i]
if len(str(ans))==n:
  print(ans)
else:
  print(-1)
