n,m=map(int,input().split())
sc=[]
flag=0
for i in range(m):
  s,c=map(int,input().split())
  if [s,c] in sc:
    continue
  else:
    sc.append([s,c])
sc.sort()

ans=-1
keta=[0 for i in range(n)]
cnt=[0,0,0]

for i in range(1,len(sc)):
  if sc[i-1][0]==sc[i][0]:
    flag=1

for i,j in sc:
  if n>1 and (i==1 and j==0):
    flag=1

if flag==0:
  if n==1:
    for i,j in sc:
      ans=j
  if n==2:
    for i,j in sc:
      if i==1:
        keta[1]=j
      if i==2:
        keta[0]=j
    if keta[1]==0:
      keta[1]=1
    ans=keta[1]*10+keta[0]

  if n==3:
    for i,j in sc:
      if i==1:
        keta[2]=j
      if i==2:
        keta[1]=j
      if i==3:
        keta[0]=j
    if keta[2]==0:
      keta[2]==1
    ans=keta[2]*100+keta[1]*10+keta[0]
print(ans)
