N,M = map(int,input().split())
v = []
h = 0
for i in range(N):
  v.append([0,0])
for i in range(M):
  s,c = map(int,input().split())
  if (v[s-1][1]==0):
    v[s-1][0]==c
    v[s-1][1]+=1
  else:
    h +=1
    break
if h>0:
  a=-1
  print(1)
elif(v[0][0]==0)and(N!=1):
  a=-1
  print(a)
else:
  print(100*v[0][0]+10*v[1][0]+v[2][0])
    
