n,m=map(int,input().split())
if m=0:
  print(0)
else:
  sc= [list(map(int,input().split())) for i in range(m)]
  ans = -1
  s=[[0 for i in range(2)] for i in range(n)]
  for j in range(10**n):
    k=str(j)
    for l in range(len(k)):
      s[l][0]=l+1
      s[l][1]=int(k[l])
    if all(elm in s for elm in sc) == 1:
      ans=j
      break
  print(ans)