n,m=map(int,input().split())
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-1)+1,10**n):
  k=str(j)
  for l in range(n):
    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)