N,M=map(int,input().split())
s=[];c=[]
anslist=[0]*N
count=[0]*N

for i in range(M):
  array=list(map(int,input().split()))
  s.append(array[0])
  c.append(array[1])

for m in range(M):
  if count[s[m]-1]>=1:
  	anslist[s[m]-1]=min(c[m],anslist[s[m]-1])
  	count[s[m]-1] +=1
  else:
    anslist[s[m]-1]=c[m]
    count[s[m]-1] += 1

if anslist[0]==0:
  print(-1)
else:
  l_n_str = [str(n) for n in anslist]
  print(int(''.join(l_n_str)))