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
for i in range(n):
  if d[i]==-1:d[i]=0
print(*d[1:n+1],sep='') 