import sys
n,m = map(int, input().split())

S = []
C = []
for _ in range(m):
  s,c = map(int, input().split())
  S.append(s)
  C.append(c)

done_s = []
done_c = []
for i in range(m):
  if S[i] in done_s:
    for j in range(len(done_s)):
      if done_s[j] == S[i] and done_c[j] != C[i]:
        print(-1)
        sys.exit()
  
  if S[i] == 1 and C[i] == 0:
    print(-1)
    sys.exit()
    
  done_s.append(S[i])
  done_c.append(C[i])
  
answer = 0
for i in range(m):
  answer += (10 ** (n - S[i]) )*C[i] 

print(answer)
