N,M =map(int,input().split())
sm={}#i:[] for i in range(10)}
for i in range(M):
  s,m=map(int,input().split())
  sm[s]=sm.get(s,[])+[m]

if sum(sum(sm.values(),[]))==0:
  print(0)
  exit()

for i in range(1,1000):
  S = str(i)
  F =True
  for s,m in sm.items():
    for j in m:
      try:
        if S[s-1]!=str(j):
          F=False
          break
      except:
        F=False
        break
  if F:
    print(i)
    exit()
print(-1)