n,m = map(int,input().split())
slist = {}
clist = {}
for i in range(M-1):
  s[i], c[i] = map(int,input().split())
 
    
  slist.append(si)
  clist.append(ci)
for n in range (M-1):
  for m in range (1,n-1):
    if (s[n] == s[m]) and (c[n] != c[m]):
      answer = -1
      print(answer)
      break
for l in range(1,M):
  answer += c[l]*10**(s[l]-1)
print(answer)
       
