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())

Flag =1 #Noなら0
sum = 0

for i in range(M):
  if s[i]==1 and c[i]==0:
    Flag = 0

for i in range(M):
  for j in range(M):
    if s[i]==s[j] and c[i]!=c[j]:
      Flag = 0

for i in range(M):
  for j in range(M):
    if s[i]==s[j] and c[i]==c[j] and i<j:
      s[j]=0
      c[j]=0

if Flag ==1:
  for i in range(M):
      sum = sum + c[i]*(10**(N-s[i]))
  print(sum)

else:
  print('-1')