n,m = map(int,input().split())
S=[0]*m
C=[0]*m
for i in range(m):
  S[i],C[i] = map(int,input().split())  
  
ans = -1
for i in range(1,10**n):
  s = str(i)
  c = 0
  for j in range(m):
    if S[j] > len(s):
      break
    if s[S[j]-1] == str(C[j]):
      c += 1  
  if c == m and len(str(i))==n :
    ans = i
    break
print(ans)  