N, M= map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)
x=[0]*N
answer=-1
for i in range(M-1):
  x[s[i]-1]=c[i]
  if not 1 in s:
    x[0]=1
if x[0]==0:
    answer=-1
else:
  x=''.join(map(str,x))
  answer=int(x)

for i in range(M-1):
  if s[i]==s[i+1] or s[i]>N:
    answer=-1
print(answer)